Error message for non-fully-qualified method lookup does not contain helpful information related to auto traits.
This is spun off from https://github.com/rust-lang/rust/issues/90601.
Given the following code (playground):
trait Foo {
fn foo(self);
}
impl<T: Send> Foo for T {
fn foo(self) {
println!("foo");
}
}
struct NotSend(Box<dyn ToString>);
fn main() {
NotSend(Box::new("hello")).foo();
}
The current output is:
error[E0599]: the method `foo` exists for struct `NotSend`, but its trait bounds were not satisfied
--> src/main.rs:14:32
|
11 | struct NotSend(Box<dyn ToString>);
| ----------------------------------
| |
| method `foo` not found for this
| doesn't satisfy `NotSend: Foo`
| doesn't satisfy `NotSend: Send`
...
14 | NotSend(Box::new("hello")).foo();
| ^^^ method cannot be called on `NotSend` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`NotSend: Send`
which is required by `NotSend: Foo`
`&NotSend: Send`
which is required by `&NotSend: Foo`
`&mut NotSend: Send`
which is required by `&mut NotSend: Foo`
note: the following trait must be implemented
By contrast, if you fully qualify the method path, you get an explanation for why the auto trait Send does not apply to your type (playground):
error[E0277]: `(dyn ToString + 'static)` cannot be sent between threads safely
--> src/main.rs:14:14
|
14 | Foo::foo(NotSend(Box::new("hello")));
| -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn ToString + 'static)` cannot be sent between threads safely
| |
| required by a bound introduced by this call
|
= help: the trait `Send` is not implemented for `(dyn ToString + 'static)`
= note: required because of the requirements on the impl of `Send` for `Unique<(dyn ToString + 'static)>`
= note: required because it appears within the type `Box<(dyn ToString + 'static)>`
note: required because it appears within the type `NotSend`
--> src/main.rs:11:8
|
11 | struct NotSend(Box<dyn ToString>);
| ^^^^^^^
note: required because of the requirements on the impl of `Foo` for `NotSend`
--> src/main.rs:5:15
|
5 | impl<T: Send> Foo for T {
| ^^^ ^
note: required by `Foo::foo`
--> src/main.rs:2:5
|
2 | fn foo(self);
| ^^^^^^^^^^^^^
I don't really have a great plan for how to integrate that extra information into the first error, but here's one proposal:
error[E0599]: the method `foo` exists for struct `NotSend`, but its trait bounds were not satisfied
--> src/main.rs:14:32
|
11 | struct NotSend(Box<dyn ToString>);
| ----------------------------------
| |
| method `foo` not found for this
| doesn't satisfy `NotSend: Foo`
| doesn't satisfy `NotSend: Send`
...
14 | NotSend(Box::new("hello")).foo();
| ^^^ method cannot be called on `NotSend` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`NotSend: Send`
which is required by `NotSend: Foo`
`&NotSend: Send`
which is required by `&NotSend: Foo`
`&mut NotSend: Send`
which is required by `&mut NotSend: Foo`
note: the trait `Send` is not implemented for `(dyn ToString + 'static)`
note: required because of the requirements on the impl of `Send` for `Unique<(dyn ToString + 'static)>`
note: required because it appears within the type `Box<(dyn ToString + 'static)>`
note: required because it appears within the type `NotSend`
--> src/main.rs:11:8
|
11 | struct NotSend(Box<dyn ToString>);
| ^^^^^^^
@rustbot label +A-traits +A-typesystem +D-terse +F-auto_traits
This is spun off from https://github.com/rust-lang/rust/issues/90601.
Given the following code (playground):
trait Foo { fn foo(self); } impl<T: Send> Foo for T { fn foo(self) { println!("foo"); } } struct NotSend(Box<dyn ToString>); fn main() { NotSend(Box::new("hello")).foo(); }The current output is:
error[E0599]: the method `foo` exists for struct `NotSend`, but its trait bounds were not satisfied --> src/main.rs:14:32 | 11 | struct NotSend(Box<dyn ToString>); | ---------------------------------- | | | method `foo` not found for this | doesn't satisfy `NotSend: Foo` | doesn't satisfy `NotSend: Send` ... 14 | NotSend(Box::new("hello")).foo(); | ^^^ method cannot be called on `NotSend` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `NotSend: Send` which is required by `NotSend: Foo` `&NotSend: Send` which is required by `&NotSend: Foo` `&mut NotSend: Send` which is required by `&mut NotSend: Foo` note: the following trait must be implementedBy contrast, if you fully qualify the method path, you get an explanation for why the auto trait
Senddoes not apply to your type (playground):error[E0277]: `(dyn ToString + 'static)` cannot be sent between threads safely --> src/main.rs:14:14 | 14 | Foo::foo(NotSend(Box::new("hello"))); | -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn ToString + 'static)` cannot be sent between threads safely | | | required by a bound introduced by this call | = help: the trait `Send` is not implemented for `(dyn ToString + 'static)` = note: required because of the requirements on the impl of `Send` for `Unique<(dyn ToString + 'static)>` = note: required because it appears within the type `Box<(dyn ToString + 'static)>` note: required because it appears within the type `NotSend` --> src/main.rs:11:8 | 11 | struct NotSend(Box<dyn ToString>); | ^^^^^^^ note: required because of the requirements on the impl of `Foo` for `NotSend` --> src/main.rs:5:15 | 5 | impl<T: Send> Foo for T { | ^^^ ^ note: required by `Foo::foo` --> src/main.rs:2:5 | 2 | fn foo(self); | ^^^^^^^^^^^^^I don't really have a great plan for how to integrate that extra information into the first error, but here's one proposal:
error[E0599]: the method `foo` exists for struct `NotSend`, but its trait bounds were not satisfied --> src/main.rs:14:32 | 11 | struct NotSend(Box<dyn ToString>); | ---------------------------------- | | | method `foo` not found for this | doesn't satisfy `NotSend: Foo` | doesn't satisfy `NotSend: Send` ... 14 | NotSend(Box::new("hello")).foo(); | ^^^ method cannot be called on `NotSend` due to unsatisfied trait bounds | = note: the following trait bounds were not satisfied: `NotSend: Send` which is required by `NotSend: Foo` `&NotSend: Send` which is required by `&NotSend: Foo` `&mut NotSend: Send` which is required by `&mut NotSend: Foo` note: the trait `Send` is not implemented for `(dyn ToString + 'static)` note: required because of the requirements on the impl of `Send` for `Unique<(dyn ToString + 'static)>` note: required because it appears within the type `Box<(dyn ToString + 'static)>` note: required because it appears within the type `NotSend` --> src/main.rs:11:8 | 11 | struct NotSend(Box<dyn ToString>); | ^^^^^^^cc https://github.com/rust-lang/rust/issues/13231
@rustbot label +A-traits +A-typesystem +D-terse +F-auto_traits
Ben Reeves at 2021-11-07 06:45:49
Current output:
error[E0599]: `NotSend` cannot be sent between threads safely --> src/main.rs:14:32 | 11 | struct NotSend(Box<dyn ToString>); | -------------- | | | method `foo` not found for this struct | doesn't satisfy `NotSend: Foo` | doesn't satisfy `NotSend: Send` ... 14 | NotSend(Box::new("hello")).foo(); | ^^^ `NotSend` cannot be sent between threads safely | note: the following trait bounds were not satisfied: `&NotSend: Send` `&mut NotSend: Send` `NotSend: Send` --> src/main.rs:5:9 | 5 | impl<T: Send> Foo for T { | ^^^^ --- - | | | unsatisfied trait bound introduced here note: the trait `Send` must be implemented --> /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/core/src/marker.rs:82:1vs the following for the fully qualified path version
error[E0277]: `(dyn ToString + 'static)` cannot be sent between threads safely --> src/main.rs:14:14 | 14 | Foo::foo(NotSend(Box::new("hello"))); | -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn ToString + 'static)` cannot be sent between threads safely | | | required by a bound introduced by this call | = help: the trait `Send` is not implemented for `(dyn ToString + 'static)` = note: required for `Unique<(dyn ToString + 'static)>` to implement `Send` note: required because it appears within the type `Box<dyn ToString>` --> /rustc/e7c502d9309ae6bc6a9750514ba7fe397844e84c/library/alloc/src/boxed.rs:195:12 note: required because it appears within the type `NotSend` --> src/main.rs:11:8 | 11 | struct NotSend(Box<dyn ToString>); | ^^^^^^^ note: required for `NotSend` to implement `Foo` --> src/main.rs:5:15 | 5 | impl<T: Send> Foo for T { | ---- ^^^ ^ | | | unsatisfied trait bound introduced hereEsteban Kuber at 2023-09-28 23:33:09
Current output, trivial changes:
error[E0599]: `NotSend` cannot be sent between threads safely --> src/main.rs:14:32 | 11 | struct NotSend(Box<dyn ToString>); | -------------- method `foo` not found for this struct because it doesn't satisfy `NotSend: Foo` or `NotSend: Send` ... 14 | NotSend(Box::new("hello")).foo(); | ^^^ `NotSend` cannot be sent between threads safely | note: the following trait bounds were not satisfied: `&NotSend: Send` `&mut NotSend: Send` `NotSend: Send` --> src/main.rs:5:9 | 5 | impl<T: Send> Foo for T { | ^^^^ --- - | | | unsatisfied trait bound introduced here note: the trait `Send` must be implemented --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/marker.rs:90:1 | 90 | pub unsafe auto trait Send { | ^^^^^^^^^^^^^^^^^^^^^^^^^^ = help: items from traits can only be used if the trait is implemented and in scope note: `Foo` defines an item `foo`, perhaps you need to implement it --> src/main.rs:1:1 | 1 | trait Foo { | ^^^^^^^^^error[E0277]: `(dyn ToString + 'static)` cannot be sent between threads safely --> src/main.rs:14:14 | 14 | Foo::foo(NotSend(Box::new("hello"))); | -------- ^^^^^^^^^^^^^^^^^^^^^^^^^^ `(dyn ToString + 'static)` cannot be sent between threads safely | | | required by a bound introduced by this call | = help: the trait `Send` is not implemented for `(dyn ToString + 'static)` = note: required for `Unique<(dyn ToString + 'static)>` to implement `Send` note: required because it appears within the type `Box<(dyn ToString + 'static)>` --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:231:12 | 231 | pub struct Box< | ^^^ note: required because it appears within the type `NotSend` --> src/main.rs:11:8 | 11 | struct NotSend(Box<dyn ToString>); | ^^^^^^^ note: required for `NotSend` to implement `Foo` --> src/main.rs:5:15 | 5 | impl<T: Send> Foo for T { | ---- ^^^ ^ | | | unsatisfied trait bound introduced hereEsteban Kuber at 2025-03-07 19:29:59