-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 warning: "unused logical operation that must be used" #69466
Comments
I don't think this is the intended use of logical operators, you should use an |
While it is a bad style to do something like this, it is also perfectly valid code. As rustc’s lints are expected to have no false-positives, this is a genuine bug. The stylistic preference should be linted by clippy, not rustc. |
For the record, I disagree that this is bad style, or it's at least debatable. It seems like it's taking advantage of the sugar that As for whether this should be linted against or not, it seems to me it should not, but cc @rust-lang/lang if there are objections. |
Pointers: The code that needs to be modified is rust/src/librustc_lint/unused.rs Lines 37 to 111 in 18c275b
I believe you will have to explore the The cases where the
|
I would just replace hir::BinOpKind::And | hir::BinOpKind::Or => Some("logical operation"), As to lint correctly you'd probably also have to look at whether there any side-effects in the RHS. |
@estebank thanks! I'll try to have a look at this and post if I have any questions :) |
triage: still an issue on latest nightly |
In a loop, in some cases, rustc seems to not understand that a boolean expression was used for sideeffects, and warns about unused logical operation. The following code can quickly replicate the problem.
The expected result is that rustc doesn't output a warning in this case.
Meta
The text was updated successfully, but these errors were encountered: