Skip to content

Incorrect hint when referring to undefined variable which shares name of field in static method #57906

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

Closed
gridbugs opened this issue Jan 25, 2019 · 1 comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`

Comments

@gridbugs
Copy link

pub struct S {
    pub foo: u32,
}

impl S {
    pub fn new() {
        let x = foo;
    }
}

The error message on 1.32 is:

error[E0425]: cannot find value `foo` in this scope
 --> src/lib.rs:7:17
  |
7 |         let x = foo;
  |                 ^^^
  |                 |
  |                 `self` value is a keyword only available in methods with `self` parameter
  |                 help: try: `self.foo`

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7c3b9f4e90adb3db85bda29574102f77

@zackmdavis zackmdavis added the A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` label Jan 25, 2019
@davidtwco
Copy link
Member

Closing, the current error message (as of #60061) is shown below. While this still mentions the field existing in Self, it no longer suggests self.foo in a function without a self parameter.

error[E0425]: cannot find value `foo` in this scope
 --> src/lib.rs:7:17
  |
7 |         let x = foo;
  |                 ^^^ a field by this name exists in `Self`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`
Projects
None yet
Development

No branches or pull requests

3 participants