Skip to content

Poor error message when using self: Box<Self> #64199

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

Closed
mtak- opened this issue Sep 6, 2019 · 2 comments
Closed

Poor error message when using self: Box<Self> #64199

mtak- opened this issue Sep 6, 2019 · 2 comments
Labels
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.

Comments

@mtak-
Copy link
Contributor

mtak- commented Sep 6, 2019

The following code produces a very confusing error message.

struct Foo;

impl Foo {
    fn consume(self: Box<Self>) {}
}

fn bar() {
    let x = Foo;
    x.consume();
}
error[E0599]: no method named `consume` found for type `Foo` in the current scope
 --> src/lib.rs:9:7
  |
1 | struct Foo;
  | ----------- method `consume` not found for this
...
9 |     x.consume();
  |       ^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `consume`, perhaps you need to implement it:
          candidate #1: `std::io::BufRead`

error: aborting due to previous error

I would expect it to mention that consume expects Box<Foo> but x is only of type Foo.

@estebank
Copy link
Contributor

estebank commented Sep 6, 2019

This should be handled by #64056. If you update to latest nightly you should see:

error[E0599]: no method named `consume` found for type `Foo` in the current scope
 --> file.rs:9:7
  |
1 | struct Foo;
  | ----------- method `consume` not found for this
...
4 |     fn consume(self: Box<Self>) {}
  |        ------- the method is available for `std::boxed::Box<Foo>` here
...
9 |     x.consume();
  |       ^^^^^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `consume`, perhaps you need to implement it:
          candidate #1: `std::io::BufRead`

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0599, E0601.
For more information about an error, try `rustc --explain E0599`.

@estebank estebank 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 Sep 6, 2019
@mtak-
Copy link
Contributor Author

mtak- commented Sep 6, 2019

Ah great thanks for the hard work!

@mtak- mtak- closed this as completed Sep 6, 2019
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 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

2 participants