diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index f511862b37b84..76bb28f7e9487 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -1359,6 +1359,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // somewhere else in the obligation chain. Do not suggest non-sense. return false; } + err.span.clear_span_labels(); + err.span_label(span, &format!( + "expected an implementor of trait `{}`", + obligation.parent_trait_ref.skip_binder(), + )); err.span_suggestion( span, "consider borrowing here", diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index b88d6dbc3f379..fc8c72e4f2320 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -736,6 +736,11 @@ impl MultiSpan { replacements_occurred } + /// This should be *rarely* used. Remove all the labels in this `MultiSpan`. + pub fn clear_span_labels(&mut self) { + self.span_labels.clear(); + } + /// Returns the strings to highlight. We always ensure that there /// is an entry for each of the primary spans -- for each primary /// span `P`, if there is at least one label with span `P`, we return diff --git a/src/test/ui/derives/deriving-copyclone.stderr b/src/test/ui/derives/deriving-copyclone.stderr index 561706469c648..e23d48ca6304b 100644 --- a/src/test/ui/derives/deriving-copyclone.stderr +++ b/src/test/ui/derives/deriving-copyclone.stderr @@ -7,7 +7,7 @@ LL | fn is_copy(_: T) {} LL | is_copy(B { a: 1, b: C }); | ^^^^^^^^^^^^^^^^ | | - | the trait `std::marker::Copy` is not implemented for `C` + | expected an implementor of trait `std::marker::Copy` | help: consider borrowing here: `&B { a: 1, b: C }` | = note: required because of the requirements on the impl of `std::marker::Copy` for `B` @@ -21,7 +21,7 @@ LL | fn is_clone(_: T) {} LL | is_clone(B { a: 1, b: C }); | ^^^^^^^^^^^^^^^^ | | - | the trait `std::clone::Clone` is not implemented for `C` + | expected an implementor of trait `std::clone::Clone` | help: consider borrowing here: `&B { a: 1, b: C }` | = note: required because of the requirements on the impl of `std::clone::Clone` for `B` @@ -35,7 +35,7 @@ LL | fn is_copy(_: T) {} LL | is_copy(B { a: 1, b: D }); | ^^^^^^^^^^^^^^^^ | | - | the trait `std::marker::Copy` is not implemented for `D` + | expected an implementor of trait `std::marker::Copy` | help: consider borrowing here: `&B { a: 1, b: D }` | = note: required because of the requirements on the impl of `std::marker::Copy` for `B` diff --git a/src/test/ui/suggestions/issue-62843.stderr b/src/test/ui/suggestions/issue-62843.stderr index 9535bf1b2ced5..ecaa39dbd2c8b 100644 --- a/src/test/ui/suggestions/issue-62843.stderr +++ b/src/test/ui/suggestions/issue-62843.stderr @@ -4,7 +4,7 @@ error[E0277]: the trait bound `std::string::String: std::str::pattern::Pattern<' LL | println!("{:?}", line.find(pattern)); | ^^^^^^^ | | - | expected an `FnMut<(char,)>` closure, found `std::string::String` + | expected an implementor of trait `std::str::pattern::Pattern<'_>` | help: consider borrowing here: `&pattern` | = help: the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String` diff --git a/src/test/ui/traits/traits-negative-impls.stderr b/src/test/ui/traits/traits-negative-impls.stderr index 448bb90205d03..cfb8b1d7b5f3c 100644 --- a/src/test/ui/traits/traits-negative-impls.stderr +++ b/src/test/ui/traits/traits-negative-impls.stderr @@ -52,7 +52,7 @@ LL | fn is_send(_: T) {} LL | is_send(Box::new(TestType)); | ^^^^^^^^^^^^^^^^^^ | | - | `dummy2::TestType` cannot be sent between threads safely + | expected an implementor of trait `std::marker::Send` | help: consider borrowing here: `&Box::new(TestType)` | = help: the trait `std::marker::Send` is not implemented for `dummy2::TestType` @@ -82,7 +82,7 @@ LL | fn is_sync(_: T) {} LL | is_sync(Outer2(TestType)); | ^^^^^^^^^^^^^^^^ | | - | `main::TestType` cannot be sent between threads safely + | expected an implementor of trait `std::marker::Sync` | help: consider borrowing here: `&Outer2(TestType)` | = help: the trait `std::marker::Send` is not implemented for `main::TestType`