diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 57cb9564f71bd..3c4db5e0e259e 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -1194,10 +1194,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // it's a actual definition. According to the comments (e.g. in // librustc_typeck/check/compare_method.rs:compare_predicate_entailment) the latter // is relied upon by some other code. This might (or might not) need cleanup. - let body_owner_def_id = match self.tcx.hir().opt_local_def_id(cause.body_id) { - Some(def_id) => def_id, - None => self.tcx.hir().body_owner_def_id(hir::BodyId{hir_id: cause.body_id}), - }; + let body_owner_def_id = self.tcx.hir().opt_local_def_id(cause.body_id) + .unwrap_or_else(|| { + self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id }) + }); self.check_and_note_conflicting_crates(diag, terr, span); self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id); diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 768487fb16267..0639a70ed0c49 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -291,14 +291,14 @@ impl<'tcx> TyCtxt<'tcx> { }, (ty::Param(expected), ty::Param(found)) => { let generics = self.generics_of(body_owner_def_id); - db.span_label( - self.def_span(generics.type_param(expected, self).def_id), - "expected type parameter" - ); - db.span_label( - self.def_span(generics.type_param(found, self).def_id), - "found type parameter" - ); + let e_span = self.def_span(generics.type_param(expected, self).def_id); + if !sp.contains(e_span) { + db.span_label(e_span, "expected type parameter"); + } + let f_span = self.def_span(generics.type_param(found, self).def_id); + if !sp.contains(f_span) { + db.span_label(f_span, "found type parameter"); + } db.note("a type parameter was expected, but a different one was found; \ you might be missing a type parameter or trait bound"); db.note("for more information, visit \ @@ -313,10 +313,10 @@ impl<'tcx> TyCtxt<'tcx> { } (ty::Param(p), _) | (_, ty::Param(p)) => { let generics = self.generics_of(body_owner_def_id); - db.span_label( - self.def_span(generics.type_param(p, self).def_id), - "this type parameter" - ); + let p_span = self.def_span(generics.type_param(p, self).def_id); + if !sp.contains(p_span) { + db.span_label(p_span, "this type parameter"); + } db.help("type parameters must be constrained to match other types"); if self.sess.teach(&db.get_code().unwrap()) { db.help("given a type parameter `T` and a method `foo`: diff --git a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr index 84fc66bb94ce3..7cb4677a2b199 100644 --- a/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr +++ b/src/test/ui/impl-trait/impl-generic-mismatch-ab.stderr @@ -5,10 +5,8 @@ LL | fn foo(&self, a: &A, b: &impl Debug); | -- type in trait ... LL | fn foo(&self, a: &impl Debug, b: &B) { } - | - ^---------- - | | || - | | |found type parameter - | | expected type parameter `B`, found type parameter `impl Debug` + | - ^^^^^^^^^^^ expected type parameter `B`, found type parameter `impl Debug` + | | | expected type parameter | = note: expected type `fn(&(), &B, &impl Debug)`