Skip to content

Commit 024f8b9

Browse files
committed
Account for rustc_on_unimplemented
1 parent 1ef6d93 commit 024f8b9

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

src/librustc/traits/error_reporting.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
774774
&mut err,
775775
&trait_ref,
776776
points_at_arg,
777+
have_alt_message,
777778
) {
778779
self.note_obligation_cause(&mut err, obligation);
779780
err.emit();
@@ -1316,6 +1317,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13161317
err: &mut DiagnosticBuilder<'tcx>,
13171318
trait_ref: &ty::Binder<ty::TraitRef<'tcx>>,
13181319
points_at_arg: bool,
1320+
has_custom_message: bool,
13191321
) -> bool {
13201322
if !points_at_arg {
13211323
return false;
@@ -1344,14 +1346,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13441346
// original type obligation, not the last one that failed, which is arbitrary.
13451347
// Because of this, we modify the error to refer to the original obligation and
13461348
// return early in the caller.
1347-
err.message = vec![(
1348-
format!(
1349-
"the trait bound `{}: {}` is not satisfied",
1350-
found,
1351-
obligation.parent_trait_ref.skip_binder(),
1352-
),
1353-
Style::NoStyle,
1354-
)];
1349+
let msg = format!(
1350+
"the trait bound `{}: {}` is not satisfied",
1351+
found,
1352+
obligation.parent_trait_ref.skip_binder(),
1353+
);
1354+
if has_custom_message {
1355+
err.note(&msg);
1356+
} else {
1357+
err.message = vec![(msg, Style::NoStyle)];
1358+
}
13551359
if snippet.starts_with('&') {
13561360
// This is already a literal borrow and the obligation is failing
13571361
// somewhere else in the obligation chain. Do not suggest non-sense.

src/test/ui/kindck/kindck-inherited-copy-bound.object_safe_for_dispatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `std::boxed::Box<{integer}>: std::marker::Copy` is not satisfied
1+
error[E0277]: the trait bound `std::boxed::Box<{integer}>: Foo` is not satisfied
22
--> $DIR/kindck-inherited-copy-bound.rs:21:16
33
|
44
LL | fn take_param<T:Foo>(foo: &T) { }

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0277]: the trait bound `std::string::String: std::str::pattern::Pattern<'_>` is not satisfied
1+
error[E0277]: expected a `std::ops::FnMut<(char,)>` closure, found `std::string::String`
22
--> $DIR/issue-62843.rs:4:32
33
|
44
LL | println!("{:?}", line.find(pattern));
@@ -7,6 +7,7 @@ LL | println!("{:?}", line.find(pattern));
77
| expected an implementor of trait `std::str::pattern::Pattern<'_>`
88
| help: consider borrowing here: `&pattern`
99
|
10+
= note: the trait bound `std::string::String: std::str::pattern::Pattern<'_>` is not satisfied
1011
= note: required because of the requirements on the impl of `std::str::pattern::Pattern<'_>` for `std::string::String`
1112

1213
error: aborting due to previous error

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn dummy2() {
4646
impl !Send for TestType {}
4747

4848
is_send(Box::new(TestType));
49-
//~^ ERROR the trait bound `dummy2::TestType: std::marker::Send` is not satisfied
49+
//~^ ERROR `dummy2::TestType` cannot be sent between threads safely
5050
}
5151

5252
fn dummy3() {
@@ -64,5 +64,5 @@ fn main() {
6464
// This will complain about a missing Send impl because `Sync` is implement *just*
6565
// for T that are `Send`. Look at #20366 and #19950
6666
is_sync(Outer2(TestType));
67-
//~^ ERROR the trait bound `main::TestType: std::marker::Sync` is not satisfied
67+
//~^ ERROR `main::TestType` cannot be sent between threads safely
6868
}

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LL | is_send((8, TestType));
4343
= help: within `({integer}, dummy1c::TestType)`, the trait `std::marker::Send` is not implemented for `dummy1c::TestType`
4444
= note: required because it appears within the type `({integer}, dummy1c::TestType)`
4545

46-
error[E0277]: the trait bound `dummy2::TestType: std::marker::Send` is not satisfied
46+
error[E0277]: `dummy2::TestType` cannot be sent between threads safely
4747
--> $DIR/traits-negative-impls.rs:48:13
4848
|
4949
LL | fn is_send<T: Send>(_: T) {}
@@ -55,6 +55,7 @@ LL | is_send(Box::new(TestType));
5555
| expected an implementor of trait `std::marker::Send`
5656
| help: consider borrowing here: `&Box::new(TestType)`
5757
|
58+
= note: the trait bound `dummy2::TestType: std::marker::Send` is not satisfied
5859
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<dummy2::TestType>`
5960
= note: required because it appears within the type `std::boxed::Box<dummy2::TestType>`
6061

@@ -72,7 +73,7 @@ LL | is_send(Box::new(Outer2(TestType)));
7273
= note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<Outer2<dummy3::TestType>>`
7374
= note: required because it appears within the type `std::boxed::Box<Outer2<dummy3::TestType>>`
7475

75-
error[E0277]: the trait bound `main::TestType: std::marker::Sync` is not satisfied
76+
error[E0277]: `main::TestType` cannot be sent between threads safely
7677
--> $DIR/traits-negative-impls.rs:66:13
7778
|
7879
LL | fn is_sync<T: Sync>(_: T) {}
@@ -84,6 +85,7 @@ LL | is_sync(Outer2(TestType));
8485
| expected an implementor of trait `std::marker::Sync`
8586
| help: consider borrowing here: `&Outer2(TestType)`
8687
|
88+
= note: the trait bound `main::TestType: std::marker::Sync` is not satisfied
8789
= note: required because of the requirements on the impl of `std::marker::Sync` for `Outer2<main::TestType>`
8890

8991
error: aborting due to 7 previous errors

0 commit comments

Comments
 (0)