Skip to content

unused_variable false positives after diverging (panic!, etc.) #148373

@p00f

Description

@p00f

Code

repo: https://git.sr.ht/~p00f/gerudo
commit: ffa7ef9034bd0285f23c43f5f417c5870092263e

Current output

❯ cargo fix --lib -p gerudo
    Checking gerudo v0.1.0 (/home/chinmay/code/projects/disasm/gerudo)
warning: failed to automatically apply fixes suggested by rustc to crate `gerudo`

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

  * src/arch/amd64/mod.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 `prefix` in this scope
   --> src/arch/amd64/mod.rs:116:16
    |
115 |             let _prefix = slice[index];
    |                 ------- `_prefix` defined here
116 |             if prefix == 0xc5 {
    |                ^^^^^^
    |
help: the leading underscore in `_prefix` marks it as unused, consider renaming it to `prefix`
    |
115 -             let _prefix = slice[index];
115 +             let prefix = slice[index];
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:120:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
119 |
120 |                 vex.with_r(two_byte_vex.r());
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `two_byte_vex` in this scope
   --> src/arch/amd64/mod.rs:120:28
    |
117 |                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |                     ------------- `_two_byte_vex` defined here
...
120 |                 vex.with_r(two_byte_vex.r());
    |                            ^^^^^^^^^^^^
    |
help: the leading underscore in `_two_byte_vex` marks it as unused, consider renaming it to `two_byte_vex`
    |
117 -                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
117 +                 let two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:121:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
121 |                 vex.with_x(u1::from(1u8));
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:122:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
122 |                 vex.with_b(u1::from(1u8));
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:123:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
123 |                 vex.with_map_select(u5::from(1u8));
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:124:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
124 |                 vex.with_w_e(u1::from(0u8));
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:125:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
125 |                 vex.with_register_select(two_byte_vex.register_select());
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `two_byte_vex` in this scope
   --> src/arch/amd64/mod.rs:125:42
    |
117 |                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |                     ------------- `_two_byte_vex` defined here
...
125 |                 vex.with_register_select(two_byte_vex.register_select());
    |                                          ^^^^^^^^^^^^
    |
help: the leading underscore in `_two_byte_vex` marks it as unused, consider renaming it to `two_byte_vex`
    |
117 -                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
117 +                 let two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:126:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
126 |                 vex.with_len(two_byte_vex.len());
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `two_byte_vex` in this scope
   --> src/arch/amd64/mod.rs:126:30
    |
117 |                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |                     ------------- `_two_byte_vex` defined here
...
126 |                 vex.with_len(two_byte_vex.len());
    |                              ^^^^^^^^^^^^
    |
help: the leading underscore in `_two_byte_vex` marks it as unused, consider renaming it to `two_byte_vex`
    |
117 -                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
117 +                 let two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:127:17
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
127 |                 vex.with_pp(two_byte_vex.pp());
    |                 ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `two_byte_vex` in this scope
   --> src/arch/amd64/mod.rs:127:29
    |
117 |                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |                     ------------- `_two_byte_vex` defined here
...
127 |                 vex.with_pp(two_byte_vex.pp());
    |                             ^^^^^^^^^^^^
    |
help: the leading underscore in `_two_byte_vex` marks it as unused, consider renaming it to `two_byte_vex`
    |
117 -                 let _two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
117 +                 let two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:129:60
    |
118 |                 let _vex = VexPrefix::default();
    |                     ---- `_vex` defined here
...
129 |                 ins.ext_prefix = Some(ExtensionPrefix::Vex(vex));
    |                                                            ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
118 -                 let _vex = VexPrefix::default();
118 +                 let vex = VexPrefix::default();
    |

error[E0425]: cannot find value `vex` in this scope
   --> src/arch/amd64/mod.rs:132:60
    |
131 |                 let _vex = VexPrefix::new_with_raw_value(<u16 as FromLe>::from_le(&slice[index + 1..=index + 2]));
    |                     ---- `_vex` defined here
132 |                 ins.ext_prefix = Some(ExtensionPrefix::Vex(vex));
    |                                                            ^^^
    |
help: the leading underscore in `_vex` marks it as unused, consider renaming it to `vex`
    |
131 -                 let _vex = VexPrefix::new_with_raw_value(<u16 as FromLe>::from_le(&slice[index + 1..=index + 2]));
131 +                 let vex = VexPrefix::new_with_raw_value(<u16 as FromLe>::from_le(&slice[index + 1..=index + 2]));
    |

error: aborting due to 15 previous errors

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

warning: unused variable: `prefix`
   --> src/arch/amd64/mod.rs:115:17
    |
115 |             let prefix = slice[index];
    |                 ^^^^^^ help: if this is intentional, prefix it with an underscore: `_prefix`
    |
    = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

warning: unused variable: `two_byte_vex`
   --> src/arch/amd64/mod.rs:117:21
    |
117 |                 let two_byte_vex = TwoByteVexPrefix::new_with_raw_value(slice[index + 1]);
    |                     ^^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_two_byte_vex`

warning: unused variable: `vex`
   --> src/arch/amd64/mod.rs:118:21
    |
118 |                 let vex = VexPrefix::default();
    |                     ^^^ help: if this is intentional, prefix it with an underscore: `_vex`

warning: unused variable: `vex`
   --> src/arch/amd64/mod.rs:131:21
    |
131 |                 let vex = VexPrefix::new_with_raw_value(<u16 as FromLe>::from_le(&slice[index + 1..=index + 2]));
    |                     ^^^ help: if this is intentional, prefix it with an underscore: `_vex`

warning: `gerudo` (lib) generated 4 warnings (run `cargo fix --lib -p gerudo` to apply 4 suggestions)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.40s

Desired output

clean output, those variables are not unused

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.93.0-nightly (82ae0ee64 2025-10-31)
binary: rustc
commit-hash: 82ae0ee6487e93bd6c05167ccb2ef3485fdbc890
commit-date: 2025-10-31
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.3

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-diagnosticsArea: Messages for errors, warnings, and lintsL-unused_variablesLint: unused_variablesT-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