Skip to content

Improve diagnostics on self types in function signature #62373

Closed
@hellow554

Description

@hellow554
struct A;

impl A {
    fn foo(self: Box<Self>) {}
}

fn main() {
    A.foo()
}

gives

error[E0599]: no method named `foo` found for type `A` in the current scope
 --> src/main.rs:8:7
  |
1 | struct A;
  | --------- method `foo` not found for this
...
8 |     A.foo()
  |       ^^^

When having a trait in scope, it looks like this:

trait B { fn foo(self: Box<Self>); }
struct A;

impl B for A {
    fn foo(self: Box<Self>) {}
}

fn main() {
    A.foo()
}
Standard Error

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `foo` found for type `A` in the current scope
 --> src/main.rs:9:7
  |
2 | struct A;
  | --------- method `foo` not found for this
...
9 |     A.foo()
  |       ^^^
  |
  = help: items from traits can only be used if the trait is implemented and in scope
  = note: the following trait defines an item `foo`, perhaps you need to implement it:
          candidate #1: `B`

Both are not ideal. Improvements are welcomed :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-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