Skip to content

Nonsensical extra diagnostics for E0425 in static methods #60057

Closed
@nagisa

Description

@nagisa
Member

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.

Activity

added
C-bugCategory: This is a bug.
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Apr 17, 2019
petrochenkov

petrochenkov commented on Apr 18, 2019

@petrochenkov
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.

added 4 commits that reference this issue on Apr 18, 2019

Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco

3459eaf

Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco

df13600

Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco

31a4e9c

Rollup merge of rust-lang#60061 - estebank:field-sugg, r=davidtwco

aa58242
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-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

      Participants

      @nagisa@estebank@jonas-schievink@petrochenkov

      Issue actions

        Nonsensical extra diagnostics for E0425 in static methods · Issue #60057 · rust-lang/rust