-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this very normal code: link
#![allow(unreachable_code)]
fn main() {
if (() = return) {}
if ((..{}) == ..{}) {}
}
The current output is the following, but removing any of the parens is an error:
Compiling playground v0.0.1 (/playground)
warning: unnecessary parentheses around `if` condition
--> src/main.rs:4:8
|
4 | if (() = return) {}
| ^ ^
|
= note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
|
4 - if (() = return) {}
4 + if () = return {}
|
warning: unnecessary parentheses around `if` condition
--> src/main.rs:5:8
|
5 | if ((..{}) == ..{}) {}
| ^ ^
|
help: remove these parentheses
|
5 - if ((..{}) == ..{}) {}
5 + if (..{}) == ..{} {}
|
warning: `playground` (bin "playground") generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.99s
Running `target/debug/playground`
This also gets cargo fix
ed incorrectly.
This need to change to look at the rhs of binops:
rust/compiler/rustc_lint/src/unused.rs
Lines 591 to 601 in 661b33f
|| (followed_by_block | |
&& match &inner.kind { | |
ExprKind::Ret(_) | |
| ExprKind::Break(..) | |
| ExprKind::Yield(..) | |
| ExprKind::Yeet(..) => true, | |
ExprKind::Range(_lhs, Some(rhs), _limits) => { | |
matches!(rhs.kind, ExprKind::Block(..)) | |
} | |
_ => parser::contains_exterior_struct_lit(&inner), | |
}) |
@rustbot label T-compiler A-lint A-diagnostics
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.