Skip to content

Commit

Permalink
Modify primary label message to be inline with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 16, 2019
1 parent f57413b commit 970503b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/librustc/traits/error_reporting.rs
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/libsyntax_pos/lib.rs
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/derives/deriving-copyclone.stderr
Expand Up @@ -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>`
Expand All @@ -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>`
Expand All @@ -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>`
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/issue-62843.stderr
Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/traits/traits-negative-impls.stderr
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down

0 comments on commit 970503b

Please sign in to comment.