Skip to content

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

Closed
@gridbugs

Description

@gridbugs
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions