Repository: rust
Issue: Autofix failing when unused variables are used in dead code 
Labels: T-compiler,C-bug,A-suggestion-diagnostics,D-invalid-suggestion

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

Example:

```rust
fn test_fn(arg: u32) -> u32 {
    todo!();

    arg + 1
}
```

This reports two errors: 
1. That `arg + 1` is unreachable, i.e. `dead_code`
2. That `arg` is unused, i.e. `unused_variables`

This makes sense because Rust removes dead code from analysis when tracking unused variables. *However*, the unused variables lint also suggests prefixing unused variables with underscores, which *should not* be provided when they are actually used in dead code. The result of running `cargo fix` on this code gives:

```
warning: failed to automatically apply fixes suggested by rustc to crate `testcrate`

after fixes were automatically applied the compiler reported errors within these files:

  * /var/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs
  * 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 `arg` in this scope
 --> src/lib.rs:4:5
  |
4 |     arg + 1
  |     ^^^ help: a local variable with a similar name exists: `_arg`

warning: unreachable expression
 --> src/lib.rs:4:5
  |
2 |     todo!();
  |     ------- any code following this expression is unreachable
3 |
4 |     arg + 1
  |     ^^^^^^^ unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0425`.
Original diagnostics will follow.

warning: unreachable expression
 --> src/lib.rs:4:5
  |
2 |     todo!();
  |     ------- any code following this expression is unreachable
3 |
4 |     arg + 1
  |     ^^^^^^^ unreachable expression
  |
  = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `arg`
 --> src/lib.rs:1:12
  |
1 | fn test_fn(arg: u32) -> u32 {
  |            ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
  |
  = note: `#[warn(unused_variables)]` on by default

warning: function `test_fn` is never used
 --> src/lib.rs:1:4
  |
1 | fn test_fn(arg: u32) -> u32 {
  |    ^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
```

This prevents `cargo fix` from working in these cases.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.74.0-nightly (84a9f4c6e 2023-08-29)
binary: rustc
commit-hash: 84a9f4c6e6f0f02bff9acc9a5e0305a1554a87fc
commit-date: 2023-08-29
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0
```