Skip to content

Improve diagnostics on self types in function signature #62373

Closed

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

Activity

  1. hellow554 commented on Jul 4, 2019

    @hellow554
    ContributorAuthor

    @rustbot modify labels: A-diagnostics T-compiler C-enhancement

  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    C-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.
    on Jul 4, 2019
  3. changed the title [-]Improve diagnostics on self types[/-] [+]Improve diagnostics on self types in function signature[/+] on Jul 4, 2019
  4. added 4 commits that reference this issue on Sep 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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