-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
False positive on 'useless_let_if_seq' #2176
Labels
S-needs-discussion
Status: Needs further discussion before merging or work can be started
Comments
Is there an idiomatic way to rewrite this? Or should we just not lint? |
oli-obk
added
the
S-needs-discussion
Status: Needs further discussion before merging or work can be started
label
Oct 26, 2017
let mut cond: bool = foo();
if cond {
// ...;
cond = bar();
}; could be rewritten as let cond = if foo() {
// ...;
bar()
} else {
false
}; but I am not certain if I can call this idiomatic. |
Well... you can also do let cond = foo() || {
// ...;
bar()
}; EDIT: oops. messed up the bool operator |
@oli-obk Thanks! And sorry for nitpicking, that changes the semantics of the original code, as we want to execute let cond = foo() && {
// ...;
bar()
}; |
bors
added a commit
that referenced
this issue
May 15, 2020
Downgrade useless_let_if_seq to nursery I feel that this lint has the wrong balance of incorrect suggestions for a default-enabled lint. The immediate code I faced was something like: ```rust fn main() { let mut good = do1(); if !do2() { good = false; } if good { println!("good"); } } fn do1() -> bool { println!("1"); false } fn do2() -> bool { println!("2"); false } ``` On this code Clippy calls it unidiomatic and suggests the following diff, which has different behavior in a way that I don't necessarily want. ```diff - let mut good = do1(); - if !do2() { - good = false; - } + let good = if !do2() { + false + } else { + do1() + }; ``` On exploring issues filed about this lint, I have found that other users have also struggled with inappropriate suggestions (#4124, #3043, #2918, #2176) and suggestions that make the code worse (#3769, #2749). Overall I believe that this lint is still at nursery quality for now and should not be enabled. --- changelog: Remove useless_let_if_seq from default set of enabled lints
bors
added a commit
that referenced
this issue
May 15, 2020
Downgrade useless_let_if_seq to nursery I feel that this lint has the wrong balance of incorrect suggestions for a default-enabled lint. The immediate code I faced was something like: ```rust fn main() { let mut good = do1(); if !do2() { good = false; } if good { println!("good"); } } fn do1() -> bool { println!("1"); false } fn do2() -> bool { println!("2"); false } ``` On this code Clippy calls it unidiomatic and suggests the following diff, which has different behavior in a way that I don't necessarily want. ```diff - let mut good = do1(); - if !do2() { - good = false; - } + let good = if !do2() { + false + } else { + do1() + }; ``` On exploring issues filed about this lint, I have found that other users have also struggled with inappropriate suggestions (#4124, #3043, #2918, #2176) and suggestions that make the code worse (#3769, #2749). Overall I believe that this lint is still at nursery quality for now and should not be enabled. --- changelog: Remove useless_let_if_seq from default set of enabled lints
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I ran
cargo clippy
against rustfmt repository, I got the following suggestion, which is incorrect:This looks similar to #975.
I am using 0.0.166.
The text was updated successfully, but these errors were encountered: