Rollup merge of #77931 - aticu:fix_60336, r=petrochenkov

Fix false positive for `unused_parens` lint

Fixes #60336
This commit is contained in:
Yuki Okushi 2020-10-20 12:11:06 +09:00 committed by GitHub
commit 378ca5e640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View File

@ -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,

View File

@ -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) {}

View File

@ -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) {}

View File

@ -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