Skip to content

Nonsensical extra diagnostics for E0425 in static methods #60057

Closed
@nagisa

Description

@nagisa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions