Skip to content

Commit

Permalink
change on_unimplented logic
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed May 16, 2016
1 parent 5458d8b commit 65ad935
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/librustc/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {

let trait_self_ty = tcx.erase_late_bound_regions(&trait_ref).self_ty();

if trait_self_ty.is_ty_var() {
return None;
}

self.tcx.lookup_trait_def(trait_ref.def_id())
.for_each_relevant_impl(self.tcx, trait_self_ty, |def_id| {
let impl_self_ty = tcx
Expand All @@ -169,17 +173,20 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
.self_ty()
.subst(tcx, &self.impl_substs(def_id, obligation.clone()));

if !tcx.has_attr(def_id, "rustc_on_unimplemented") {
return;
}

if let Ok(..) = self.can_equate(&trait_self_ty, &impl_self_ty) {
ambiguous = result.is_some();
result = Some(def_id);
}
});

match result {
Some(def_id) if !ambiguous && tcx.has_attr(def_id, "rustc_on_unimplemented") => {
result
}
_ => None
if ambiguous {
None
} else {
result
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/compile-fail/check_on_unimplemented_on_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

#![feature(rustc_attrs)]

use std::ops::Index;

#[rustc_error]
fn main() {
let x = &[1, 2, 3] as &[i32];
Expand Down

0 comments on commit 65ad935

Please sign in to comment.