Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused_variable: applying suggestion causes compiler error #104904

Closed
matthiaskrgr opened this issue Nov 25, 2022 · 4 comments
Closed

unused_variable: applying suggestion causes compiler error #104904

matthiaskrgr opened this issue Nov 25, 2022 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Given the following code:

fn main() {
    let res = { if true { return; } else { return; }; }; if res {}
}

The current output is:

warning: unreachable expression
 --> src/main.rs:2:58
  |
2 |     let res = { if true { return; } else { return; }; }; if res {}
  |                           ------                         ^^^^^^^^^ unreachable expression
  |                           |
  |                           any code following this expression is unreachable
  |
  = note: `#[warn(unreachable_code)]` on by default

warning: unused variable: `res`
 --> src/main.rs:2:9
  |
2 |     let res = { if true { return; } else { return; }; }; if res {}
  |         ^^^ help: if this is intentional, prefix it with an underscore: `_res`
  |

The problem is while the if res {} at the end is technically unreachable, it will still cause a compiler error if we auto-apply the let res = .. -> let _res = ... with cargo fix.

Could we somehow make the "remove if res {}" suggestion apply automatically so that it is performed before the res to _res rename?

@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 25, 2022
@camsteffen
Copy link
Contributor

@ehuss
Copy link
Contributor

ehuss commented May 6, 2023

I'm going to close as a duplicate of #104904.

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2023
@matthiaskrgr
Copy link
Member Author

@ehuss this IS #104904 😅

@ehuss
Copy link
Contributor

ehuss commented May 6, 2023

Sorry, copy/paste error. 😄 It should have been #107734.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants