Skip to content

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

Closed
@mtak-

Description

@mtak-

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions