Skip to content

Suggest changing _x to x instead of a use of x to _x #60164

Closed
@oli-obk

Description

Variables can be marked as unused by prepending with an underscore. If at some point such a variable is used again, the compiler suggests to name the use _x, even though every single time I have encountered this, what I wanted is to change the definition of _x to x.

fn main() {
    let _x = 42;
    let y = x;
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0465]: multiple rlib candidates for `debug_unreachable` found
  |
  = note: candidate #1: /playground/target/debug/deps/libdebug_unreachable-aa3385f4476cae47.rlib
  = note: candidate #2: /playground/target/debug/deps/libdebug_unreachable-661505f3db863158.rlib

error[E0425]: cannot find value `x` in this scope
 --> src/main.rs:3:13
  |
3 |     let y = x;
  |             ^ help: a local variable with a similar name exists: `_x`

error: aborting due to 2 previous errors

Some errors occurred: E0425, E0465.
For more information about an error, try `rustc --explain E0425`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

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-enhancementCategory: An issue proposing an enhancement or a PR with one.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