Repository: rust
Issue: Error message for non-fully-qualified method lookup does not contain helpful information related to auto traits.
Labels: A-type-system,A-diagnostics,A-trait-system,T-compiler,D-terse,F-auto_traits,T-types

This is spun off from https://github.com/rust-lang/rust/issues/90601.

Given the following code ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=369407d93d9ef82aa667c1913ba5e236)):

```rust
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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=ebc76aa34a2261b679b709085c6c936f)):

```
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