From 65ad935737138eb307fdd01279ba5553a047bb6c Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Mon, 16 May 2016 23:16:52 +0300 Subject: [PATCH] change on_unimplented logic --- src/librustc/traits/error_reporting.rs | 17 ++++++++++++----- .../check_on_unimplemented_on_slice.rs | 2 ++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index df8cfd73192f2..847aade630f6e 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 d594b1cea8bce..6f4b211452c82 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];