]> git.lizzy.rs Git - rust.git/commitdiff
change on_unimplented logic
authorAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 16 May 2016 20:16:52 +0000 (23:16 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Mon, 16 May 2016 20:16:52 +0000 (23:16 +0300)
src/librustc/traits/error_reporting.rs
src/test/compile-fail/check_on_unimplemented_on_slice.rs

index df8cfd73192f266973441a4c71611f15d48263ce..847aade630f6eafd1753162c02c058704edcafd9 100644 (file)
@@ -161,6 +161,10 @@ fn impl_with_self_type_of(&self,
 
         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 @@ fn impl_with_self_type_of(&self,
                     .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
         }
     }
 
index d594b1cea8bce38d74f47f1576bc68ce4cbafdcf..6f4b211452c8215a4c2663f8a2c1508f747ed968 100644 (file)
@@ -12,6 +12,8 @@
 
 #![feature(rustc_attrs)]
 
+use std::ops::Index;
+
 #[rustc_error]
 fn main() {
     let x = &[1, 2, 3] as &[i32];