Skip to content

Incorrect suggestion for "a constant with a similar name exists" #163324

Description

@scrabsha

Code

const A: usize = 0;

struct S {
    a: usize,
}

fn main() {
    S { a };
}

Current output

error[E0425]: cannot find value `a` in this scope
 --> src/main.rs:8:9
  |
1 | const A: usize = 0;
  | ------------------- similarly named constant `A` defined here
...
8 |     S { a };
  |         ^
  |
help: a constant with a similar name exists
  |
8 -     S { a };
8 +     S { A };
  |

For more information about this error, try `rustc --explain E0425`.

Desired output

error[E0425]: cannot find value `a` in this scope
 --> src/main.rs:8:9
  |
1 | const A: usize = 0;
  | ------------------- similarly named constant `A` defined here
...
8 |     S { a };
  |         ^
  |
help: a constant with a similar name exists
  |
8 -     S { a };
8 +     S { a: A };
  |

For more information about this error, try `rustc --explain E0425`.

Rationale and extra context

Suggestion is incorrect, it needs to turns the initialization shorthand into a full field: expression initialization.

Other cases

Rust Version

$ rustc --version --verbose
rustc 1.98.1 (48a229cea 2026-09-01)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: x86_64-unknown-linux-gnu
release: 1.98.1
LLVM version: 22.1.8

Anything else?

@rustbot labels "+good first issue"

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Sep 25, 2026
  2. rustbot commented on Sep 25, 2026

    @rustbot
    Collaborator

    Error: Label good first issue can only be set by Rust team members

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.

  3. raushan728 commented on Sep 25, 2026

    @raushan728
    Contributor

    @rustbot claim

  4. maxdexh commented on Sep 25, 2026

    @maxdexh
    Member

    @rustbot label D-incorrect E-easy

  5. added
    D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    on Sep 25, 2026
  6. maxdexh commented on Sep 25, 2026

    @maxdexh
    Member

    @scrabsha rustbot is lying to you, the label doesn't exist ^^

  7. scrabsha commented on Sep 25, 2026

    @scrabsha
    ContributorAuthor

    i think i copied it from the rustc dev guide >//<

  8. added a commit that references this issue on Sep 29, 2026
    dd4bda9
  9. added a commit that references this issue on Sep 29, 2026
    252bb61
  10. added a commit that references this issue on Sep 30, 2026
    94c7bad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.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