Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for non-fully-qualified method lookup does not contain helpful information related to auto traits. #90664

Open
BGR360 opened this issue Nov 7, 2021 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system A-typesystem Area: The type system D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-auto_traits `#![feature(auto_traits)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BGR360
Copy link
Contributor

BGR360 commented Nov 7, 2021

This is spun off from #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>);
   |        ^^^^^^^

cc #13231

@rustbot label +A-traits +A-typesystem +D-terse +F-auto_traits

@BGR360 BGR360 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 7, 2021
@rustbot rustbot added A-traits Area: Trait system A-typesystem Area: The type system D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-auto_traits `#![feature(auto_traits)]` labels Nov 7, 2021
@estebank
Copy link
Contributor

estebank commented Sep 28, 2023

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:1

vs 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 here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system A-typesystem Area: The type system D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. F-auto_traits `#![feature(auto_traits)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants