mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Fixed false positive for unused_parens
lint
This commit is contained in:
parent
adef9da30f
commit
39867f3c9f
@ -751,13 +751,20 @@ impl UnusedDelimLint for UnusedParens {
|
||||
if !Self::is_expr_delims_necessary(inner, followed_by_block)
|
||||
&& value.attrs.is_empty()
|
||||
&& !value.span.from_expansion()
|
||||
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
|
||||
|| match inner.kind {
|
||||
ast::ExprKind::Binary(
|
||||
rustc_span::source_map::Spanned { node, .. },
|
||||
_,
|
||||
_,
|
||||
) if node.lazy() => false,
|
||||
_ => true,
|
||||
})
|
||||
{
|
||||
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
|
||||
}
|
||||
}
|
||||
ast::ExprKind::Let(_, ref expr) => {
|
||||
// FIXME(#60336): Properly handle `let true = (false && true)`
|
||||
// actually needing the parenthesis.
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
expr,
|
||||
|
@ -60,6 +60,8 @@ fn main() {
|
||||
if (v == X { y: true }) {}
|
||||
if (X { y: true } == v) {}
|
||||
if (X { y: false }.y) {}
|
||||
// this shouldn't warn, because the parens are necessary to disambiguate let chains
|
||||
if let true = (true && false) {}
|
||||
|
||||
while (X { y: false }.foo(true)) {}
|
||||
while (true | X { y: false }.y) {}
|
||||
|
@ -60,6 +60,8 @@ fn main() {
|
||||
if (v == X { y: true }) {}
|
||||
if (X { y: true } == v) {}
|
||||
if (X { y: false }.y) {}
|
||||
// this shouldn't warn, because the parens are necessary to disambiguate let chains
|
||||
if let true = (true && false) {}
|
||||
|
||||
while (X { y: false }.foo(true)) {}
|
||||
while (true | X { y: false }.y) {}
|
||||
|
@ -83,25 +83,25 @@ LL | while let 1 = (2) {}
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around method argument
|
||||
--> $DIR/lint-unnecessary-parens.rs:71:24
|
||||
--> $DIR/lint-unnecessary-parens.rs:73:24
|
||||
|
|
||||
LL | X { y: false }.foo((true));
|
||||
| ^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:73:18
|
||||
--> $DIR/lint-unnecessary-parens.rs:75:18
|
||||
|
|
||||
LL | let mut _a = (0);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:74:10
|
||||
--> $DIR/lint-unnecessary-parens.rs:76:10
|
||||
|
|
||||
LL | _a = (0);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary parentheses around assigned value
|
||||
--> $DIR/lint-unnecessary-parens.rs:75:11
|
||||
--> $DIR/lint-unnecessary-parens.rs:77:11
|
||||
|
|
||||
LL | _a += (1);
|
||||
| ^^^ help: remove these parentheses
|
||||
|
Loading…
Reference in New Issue
Block a user