Skip to content

Unused variable warning for used variable. #85071

Closed
@koehlma

Description

@koehlma

When trying to compile the following code I get an unused variable warning despite the variable is being used:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=66167b96f0e14d53616abbd0e6b3d12c

The current output is:

warning: unused variable: `typ`
  --> src/lib.rs:62:17
   |
62 |             let typ = T::infer_type(self);
   |                 ^^^ help: if this is intentional, prefix it with an underscore: `_typ`
   |
   = note: `#[warn(unused_variables)]` on by default

Ideally the output should not produce such a warning.

cargo fix produces the following output:

warning: failed to automatically apply fixes suggested by rustc to crate `rust_playground`

after fixes were automatically applied the compiler reported errors within these files:

  * src\lib.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0425]: cannot find value `typ` in this scope
  --> src\lib.rs:64:30
   |
64 |             info.typ.replace(typ);
   |                              ^^^ help: a local variable with a similar name exists: `_typ`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
Original diagnostics will follow.

warning: unused variable: `typ`
  --> src\lib.rs:62:17
   |
62 |             let typ = T::infer_type(self);
   |                 ^^^ help: if this is intentional, prefix it with an underscore: `_typ`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

warning: unused variable: `typ`
  --> src\lib.rs:62:17
   |
62 |             let typ = T::infer_type(self);
   |                 ^^^ help: if this is intentional, prefix it with an underscore: `_typ`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 1.04s

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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