Skip to content

Commit 03e4700

Browse files
committed
Modify primary label message to be inline with error message
1 parent bc5c988 commit 03e4700

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

src/librustc/traits/error_reporting.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13571357
// somewhere else in the obligation chain. Do not suggest non-sense.
13581358
return false;
13591359
}
1360+
err.span.clear_span_labels();
1361+
err.span_label(span, &format!(
1362+
"expected an implementor of trait `{}`",
1363+
obligation.parent_trait_ref.skip_binder(),
1364+
));
13601365
err.span_suggestion(
13611366
span,
13621367
"consider borrowing here",

src/libsyntax_pos/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,11 @@ impl MultiSpan {
735735
replacements_occurred
736736
}
737737

738+
/// This should be *rarely* used. Remove all the labels in this `MultiSpan`.
739+
pub fn clear_span_labels(&mut self) {
740+
self.span_labels.clear();
741+
}
742+
738743
/// Returns the strings to highlight. We always ensure that there
739744
/// is an entry for each of the primary spans -- for each primary
740745
/// span `P`, if there is at least one label with span `P`, we return

src/test/ui/derives/deriving-copyclone.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fn is_copy<T: Copy>(_: T) {}
77
LL | is_copy(B { a: 1, b: C });
88
| ^^^^^^^^^^^^^^^^
99
| |
10-
| the trait `std::marker::Copy` is not implemented for `C`
10+
| expected an implementor of trait `std::marker::Copy`
1111
| help: consider borrowing here: `&B { a: 1, b: C }`
1212
|
1313
= 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) {}
2121
LL | is_clone(B { a: 1, b: C });
2222
| ^^^^^^^^^^^^^^^^
2323
| |
24-
| the trait `std::clone::Clone` is not implemented for `C`
24+
| expected an implementor of trait `std::clone::Clone`
2525
| help: consider borrowing here: `&B { a: 1, b: C }`
2626
|
2727
= 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) {}
3535
LL | is_copy(B { a: 1, b: D });
3636
| ^^^^^^^^^^^^^^^^
3737
| |
38-
| the trait `std::marker::Copy` is not implemented for `D`
38+
| expected an implementor of trait `std::marker::Copy`
3939
| help: consider borrowing here: `&B { a: 1, b: D }`
4040
|
4141
= note: required because of the requirements on the impl of `std::marker::Copy` for `B<D>`

src/test/ui/suggestions/issue-62843.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0277]: the trait bound `std::string::String: std::str::pattern::Pattern<'
44
LL | println!("{:?}", line.find(pattern));
55
| ^^^^^^^
66
| |
7-
| expected an `FnMut<(char,)>` closure, found `std::string::String`
7+
| expected an implementor of trait `std::str::pattern::Pattern<'_>`
88
| help: consider borrowing here: `&pattern`
99
|
1010
= help: the trait `std::ops::FnMut<(char,)>` is not implemented for `std::string::String`

src/test/ui/traits/traits-negative-impls.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ LL | fn is_send<T: Send>(_: T) {}
5252
LL | is_send(Box::new(TestType));
5353
| ^^^^^^^^^^^^^^^^^^
5454
| |
55-
| `dummy2::TestType` cannot be sent between threads safely
55+
| expected an implementor of trait `std::marker::Send`
5656
| help: consider borrowing here: `&Box::new(TestType)`
5757
|
5858
= help: the trait `std::marker::Send` is not implemented for `dummy2::TestType`
@@ -82,7 +82,7 @@ LL | fn is_sync<T: Sync>(_: T) {}
8282
LL | is_sync(Outer2(TestType));
8383
| ^^^^^^^^^^^^^^^^
8484
| |
85-
| `main::TestType` cannot be sent between threads safely
85+
| expected an implementor of trait `std::marker::Sync`
8686
| help: consider borrowing here: `&Outer2(TestType)`
8787
|
8888
= help: the trait `std::marker::Send` is not implemented for `main::TestType`

0 commit comments

Comments
 (0)