Fix false positive in unused_parens caused by break
This commit is contained in:
parent
ba284f468c
commit
4803644df9
2 changed files with 29 additions and 1 deletions
|
|
@ -794,7 +794,10 @@ trait UnusedDelimLint {
|
|||
|
||||
ExprKind::Break(_label, None) => return false,
|
||||
ExprKind::Break(_label, Some(break_expr)) => {
|
||||
return matches!(break_expr.kind, ExprKind::Block(..));
|
||||
// `if (break 'label i) { ... }` removing parens would make `i { ... }`
|
||||
// be parsed as a struct literal, so keep parentheses if the break value
|
||||
// ends with a path (which could be mistaken for a struct name).
|
||||
return matches!(break_expr.kind, ExprKind::Block(..) | ExprKind::Path(..));
|
||||
}
|
||||
|
||||
ExprKind::Range(_lhs, Some(rhs), _limits) => {
|
||||
|
|
|
|||
25
tests/ui/lint/unused-parens-labeled-break-issue-143256.rs
Normal file
25
tests/ui/lint/unused-parens-labeled-break-issue-143256.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
//@ check-pass
|
||||
// testcase for https://github.com/rust-lang/rust/issues/143256
|
||||
|
||||
#![deny(unused_parens)]
|
||||
#![allow(unreachable_code, unused_variables, dead_code)]
|
||||
|
||||
fn foo() {
|
||||
let _x = || 'outer: loop {
|
||||
let inner = 'inner: loop {
|
||||
let i = Default::default();
|
||||
// the parentheses here are necessary
|
||||
if (break 'outer i) {
|
||||
loop {
|
||||
break 'inner 5i8;
|
||||
}
|
||||
} else if true {
|
||||
break 'inner 6;
|
||||
}
|
||||
break 7;
|
||||
};
|
||||
break inner < 8;
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue