Skip to content

Commit 378ca5e

Browse files
authored
Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov
Fix false positive for `unused_parens` lint Fixes #60336
2 parents 6df79bf + 39867f3 commit 378ca5e

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Diff for: compiler/rustc_lint/src/unused.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,20 @@ impl UnusedDelimLint for UnusedParens {
751751
if !Self::is_expr_delims_necessary(inner, followed_by_block)
752752
&& value.attrs.is_empty()
753753
&& !value.span.from_expansion()
754+
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
755+
|| match inner.kind {
756+
ast::ExprKind::Binary(
757+
rustc_span::source_map::Spanned { node, .. },
758+
_,
759+
_,
760+
) if node.lazy() => false,
761+
_ => true,
762+
})
754763
{
755764
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
756765
}
757766
}
758767
ast::ExprKind::Let(_, ref expr) => {
759-
// FIXME(#60336): Properly handle `let true = (false && true)`
760-
// actually needing the parenthesis.
761768
self.check_unused_delims_expr(
762769
cx,
763770
expr,

Diff for: src/test/ui/lint/lint-unnecessary-parens.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ fn main() {
6060
if (v == X { y: true }) {}
6161
if (X { y: true } == v) {}
6262
if (X { y: false }.y) {}
63+
// this shouldn't warn, because the parens are necessary to disambiguate let chains
64+
if let true = (true && false) {}
6365

6466
while (X { y: false }.foo(true)) {}
6567
while (true | X { y: false }.y) {}

Diff for: src/test/ui/lint/lint-unnecessary-parens.rs

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ fn main() {
6060
if (v == X { y: true }) {}
6161
if (X { y: true } == v) {}
6262
if (X { y: false }.y) {}
63+
// this shouldn't warn, because the parens are necessary to disambiguate let chains
64+
if let true = (true && false) {}
6365

6466
while (X { y: false }.foo(true)) {}
6567
while (true | X { y: false }.y) {}

Diff for: src/test/ui/lint/lint-unnecessary-parens.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,25 @@ LL | while let 1 = (2) {}
8383
| ^^^ help: remove these parentheses
8484

8585
error: unnecessary parentheses around method argument
86-
--> $DIR/lint-unnecessary-parens.rs:71:24
86+
--> $DIR/lint-unnecessary-parens.rs:73:24
8787
|
8888
LL | X { y: false }.foo((true));
8989
| ^^^^^^ help: remove these parentheses
9090

9191
error: unnecessary parentheses around assigned value
92-
--> $DIR/lint-unnecessary-parens.rs:73:18
92+
--> $DIR/lint-unnecessary-parens.rs:75:18
9393
|
9494
LL | let mut _a = (0);
9595
| ^^^ help: remove these parentheses
9696

9797
error: unnecessary parentheses around assigned value
98-
--> $DIR/lint-unnecessary-parens.rs:74:10
98+
--> $DIR/lint-unnecessary-parens.rs:76:10
9999
|
100100
LL | _a = (0);
101101
| ^^^ help: remove these parentheses
102102

103103
error: unnecessary parentheses around assigned value
104-
--> $DIR/lint-unnecessary-parens.rs:75:11
104+
--> $DIR/lint-unnecessary-parens.rs:77:11
105105
|
106106
LL | _a += (1);
107107
| ^^^ help: remove these parentheses

0 commit comments

Comments
 (0)