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

manual_let_else produces wrong variable name #10171

Closed
ericwu17 opened this issue Jan 6, 2023 · 2 comments · Fixed by #10175
Closed

manual_let_else produces wrong variable name #10171

ericwu17 opened this issue Jan 6, 2023 · 2 comments · Fixed by #10175
Labels
C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@ericwu17
Copy link
Contributor

ericwu17 commented Jan 6, 2023

Description

Take the following line of code (which appears in the ui test for manual_let_else):

let v = if let Some(v_some) = g() { v_some } else { return };

which declares a new variable called v. If we run clippy on the following code, we get the suggestion to replace it with

if let Some(v_some) = g() { v_some } else { return };

which declares a new variable called v_some.

The suggestion should be:

-if let Some(v_some) = g() { v_some } else { return };
+if let Some(v) = g() { v_some } else { return };

Please correct me if I'm wrong, but it looks like we have unit tests that are generating the wrong output.

Version

rustc 1.68.0-nightly (574b64a97 2022-12-31)
binary: rustc
commit-hash: 574b64a97f52162f965bc201e47f0af8279ca65d
commit-date: 2022-12-31
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6

Additional Labels

No response

@Alexendoo Alexendoo added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions labels Jan 7, 2023
@est31
Copy link
Member

est31 commented Jan 11, 2023

As a workaround, you can use rust-analyzer's match-to-let-else assist. It doesn't fire 100% in the same set of instances that clippy fires, but its logic can edit patterns which fixes a lot of the issues with autosuggestions.

@est31
Copy link
Member

est31 commented Jan 11, 2023

Also this is a dupe of #9939

@bors bors closed this as completed in 7e18451 May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants