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

Nonsensical extra diagnostics for E0425 in static methods #60057

Closed
nagisa opened this issue Apr 17, 2019 · 1 comment · Fixed by #60061
Closed

Nonsensical extra diagnostics for E0425 in static methods #60057

nagisa opened this issue Apr 17, 2019 · 1 comment · Fixed by #60061
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

nagisa commented Apr 17, 2019

The following code (playground):

struct A {
    banana: u8,
}

impl A {
    fn new(peach: u8) -> A {
        A {
            banana: banana // note: banana not in scope here
        }
    }
}

produces the following error:

error[E0425]: cannot find value `banana` in this scope
 --> src/lib.rs:8:21
  |
8 |             banana: banana
  |                     ^^^^^^
  |                     |
  |                     `self` value is a keyword only available in methods with `self` parameter
  |                     help: try: `self.banana`

First, help is wrong, because this is a static method and self is not available in scope. Second it is not clear why a line above help is talking about self at all.

@nagisa nagisa added the A-diagnostics Area: Messages for errors, warnings, and lints label Apr 17, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 17, 2019
@estebank estebank added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Apr 18, 2019
@petrochenkov
Copy link
Contributor

The original logic was to

  1. recommend self.banana, that's a common mistake
  2. then recommend adding self assuming it's forgotten, that's also a common mistake, which is especially likely if you are referring to something that is named exactly like a field.

Unfortunately, the messages were reworded and repositioned by later changes.

Centril added a commit to Centril/rust that referenced this issue Apr 18, 2019
Change suggestion of field when not in self context

Fix rust-lang#60057.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Change suggestion of field when not in self context

Fix rust-lang#60057.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Change suggestion of field when not in self context

Fix rust-lang#60057.
Centril added a commit to Centril/rust that referenced this issue Apr 19, 2019
Change suggestion of field when not in self context

Fix rust-lang#60057.
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. 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.

4 participants