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

Improve diagnostics on self types in function signature #62373

Closed
hellow554 opened this issue Jul 4, 2019 · 1 comment · Fixed by #64056
Closed

Improve diagnostics on self types in function signature #62373

hellow554 opened this issue Jul 4, 2019 · 1 comment · Fixed by #64056
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@hellow554
Copy link
Contributor

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

@hellow554
Copy link
Contributor Author

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

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 4, 2019
@hellow554 hellow554 changed the title Improve diagnostics on self types Improve diagnostics on self types in function signature Jul 4, 2019
@estebank estebank added the A-traits Area: Trait system label Jul 25, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 1, 2019
…ntril

Account for arbitrary self types in E0599

Fix rust-lang#62373
Centril added a commit to Centril/rust that referenced this issue Sep 3, 2019
…ntril

Account for arbitrary self types in E0599

Fix rust-lang#62373
Centril added a commit to Centril/rust that referenced this issue Sep 3, 2019
…ntril

Account for arbitrary self types in E0599

Fix rust-lang#62373
@bors bors closed this as completed in 56d00e3 Sep 3, 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 A-traits Area: Trait system C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants