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

Activity

davidtwco

davidtwco commented on May 4, 2019

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

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

        Participants

        @gridbugs@zackmdavis@davidtwco

        Issue actions

          Incorrect hint when referring to undefined variable which shares name of field in static method · Issue #57906 · rust-lang/rust