Skip to content

Wrong suggestion for unused_variables accepted by cargo fix #147303

Closed

Description

@crumblingstatue

Seems to originate from #145827.

Test code:

mod m1 {
    const _MAX_FMTVER_X1X_EVENTNUM: i32 = 0;
}

mod m2 {
    fn fun(rough: i32) {}
}

Gives bizarre suggestion:

help: you might have meant to pattern match on the similarly named constant `_MAX_FMTVER_X1X_EVENTNUM`
  |
6 -     fn fun(rough: i32) {}
6 +     fn fun(m1::_MAX_FMTVER_X1X_EVENTNUM: i32) {}

Which is then applied by cargo fix:

warning: failed to automatically apply fixes suggested by rustc to crate `lol`
...
The following errors were reported:
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `m1`
 --> src/lib.rs:6:12
  |
6 |     fn fun(m1::_MAX_FMTVER_X1X_EVENTNUM: i32) {}
  |            ^^ use of unresolved module or unlinked crate `m1`
  |
  = help: if you wanted to use a crate named `m1`, use `cargo add m1` to add it to your `Cargo.toml`
help: consider importing this module
  |
6 +     use crate::m1;

rustc 1.92.0-nightly (5c7ae0c7e 2025-10-02)

This is a regression from stable to nightly.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 3, 2025
  2. Jules-Bertholet commented on Oct 3, 2025

    @Jules-Bertholet
  3. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
    D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    C-bugCategory: This is a bug.
    on Oct 3, 2025
  4. self-assigned this
    on Oct 4, 2025
  5. added and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 4, 2025
  6. added 9 commits that reference this issue on Oct 4, 2025
    636a744
    2a5c6ed
    91c4d7e
    0261572
    12f8194
    5107bd7
    a3355a0
    c64c7bf
    9259b14
  7. added a commit that references this issue on Oct 5, 2025
  8. added 2 commits that reference this issue on Oct 5, 2025
  9. added 2 commits that reference this issue on Oct 5, 2025
    b621d3f
    313bbf1
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 lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.L-unused_variablesLint: unused_variablesP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions