Modify primary label message to be inline with error message

This commit is contained in:
Esteban Küber 2019-10-15 19:09:15 -07:00
parent f57413b717
commit 970503b2e1
5 changed files with 16 additions and 6 deletions

View File

@ -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",

View File

@ -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

View File

@ -7,7 +7,7 @@ LL | fn is_copy<T: 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<C>`
@ -21,7 +21,7 @@ LL | fn is_clone<T: 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<C>`
@ -35,7 +35,7 @@ LL | fn is_copy<T: 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<D>`

View File

@ -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`

View File

@ -52,7 +52,7 @@ LL | fn is_send<T: 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: 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`