Skip to content

needless_bool provides incorrect suggestions with if-else-if-else chains #4334

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

Closed
phansch opened this issue Aug 4, 2019 · 0 comments · Fixed by #4335
Closed

needless_bool provides incorrect suggestions with if-else-if-else chains #4334

phansch opened this issue Aug 4, 2019 · 0 comments · Fixed by #4335
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions

Comments

@phansch
Copy link
Member

phansch commented Aug 4, 2019

Part of #3630

Given the following code:

#![warn(clippy::needless_bool)]

let returns_bool = || false;
let x = if b {
    true
} else if returns_bool() {
    false
} else {
    true
};

we currently provide a broken suggestion:

LL |       } else if returns_bool() {
   |  ____________^
LL | |         false
LL | |     } else {
LL | |         true
LL | |     };
   | |_____^ help: you can reduce it to: `!returns_bool()`

Applying the suggestion results in a syntax error:

let x = if b {
    true
} else !returns_bool();

The suggestion should be { !returns_bool() } - as it was before this PR: rust-lang/rust#61074

@phansch phansch added C-bug Category: Clippy is not doing the correct thing L-suggestion Lint: Improving, adding or fixing lint suggestions I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied labels Aug 4, 2019
phansch added a commit to phansch/rust-clippy that referenced this issue Aug 4, 2019
bors added a commit that referenced this issue Aug 5, 2019
Fix needless_bool suggestion with if--else-if--else

changelog: Fix `needless_bool` suggestion with if--else-if--else

Closes #4334
phansch added a commit to phansch/rust-clippy that referenced this issue Aug 5, 2019
bors added a commit that referenced this issue Aug 5, 2019
Fix needless_bool suggestion with if--else-if--else

changelog: Fix `needless_bool` suggestion with if--else-if--else

Closes #4334
@bors bors closed this as completed in #4335 Aug 5, 2019
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 I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied L-suggestion Lint: Improving, adding or fixing lint suggestions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant