]> git.lizzy.rs Git - rust.git/commitdiff
Do not ICE on generics mismatch with non-local traits
authorShotaro Yamada <sinkuu@sinkuu.xyz>
Mon, 23 Apr 2018 04:54:09 +0000 (13:54 +0900)
committerShotaro Yamada <sinkuu@sinkuu.xyz>
Thu, 26 Apr 2018 12:56:21 +0000 (21:56 +0900)
Fixes #49841

src/librustc_typeck/check/compare_method.rs
src/test/compile-fail/impl-trait/impl-generic-mismatch.rs

index e1e3dea9a2a11c83167f7e34dce34e5adcd7ad9d..2003e0cc3d28f721f3676c84ceedf5c78793d000 100644 (file)
@@ -730,8 +730,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
         if impl_ty.synthetic != trait_ty.synthetic {
             let impl_node_id = tcx.hir.as_local_node_id(impl_ty.def_id).unwrap();
             let impl_span = tcx.hir.span(impl_node_id);
-            let trait_node_id = tcx.hir.as_local_node_id(trait_ty.def_id).unwrap();
-            let trait_span = tcx.hir.span(trait_node_id);
+            let trait_span = tcx.def_span(trait_ty.def_id);
             let mut err = struct_span_err!(tcx.sess,
                                            impl_span,
                                            E0643,
index eea7ca20957804739792ebefe4e44dbc52905658..d6707f590113ce5e464edd019ca0b55225d610e1 100644 (file)
@@ -28,4 +28,15 @@ fn bar(&self, _: &impl Debug) { }
     //~^ Error method `bar` has incompatible signature for trait
 }
 
+// With non-local trait (#49841):
+
+use std::hash::{Hash, Hasher};
+
+struct X;
+
+impl Hash for X {
+    fn hash(&self, hasher: &mut impl Hasher) {}
+    //~^ Error method `hash` has incompatible signature for trait
+}
+
 fn main() {}