diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index df8cfd73192..847aade630f 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -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 @@ -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 } } diff --git a/src/test/compile-fail/check_on_unimplemented_on_slice.rs b/src/test/compile-fail/check_on_unimplemented_on_slice.rs index d594b1cea8b..6f4b211452c 100644 --- a/src/test/compile-fail/check_on_unimplemented_on_slice.rs +++ b/src/test/compile-fail/check_on_unimplemented_on_slice.rs @@ -12,6 +12,8 @@ #![feature(rustc_attrs)] +use std::ops::Index; + #[rustc_error] fn main() { let x = &[1, 2, 3] as &[i32];