Do not trigger unused_braces
for while let
This commit is contained in:
parent
19ecce332e
commit
2e5c50195a
@ -520,7 +520,10 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
|
||||
(cond, UnusedDelimsCtx::IfCond, true, Some(left), Some(right))
|
||||
}
|
||||
|
||||
While(ref cond, ref block, ..) => {
|
||||
// Do not lint `unused_braces` in `while let` expressions.
|
||||
While(ref cond, ref block, ..)
|
||||
if !matches!(cond.kind, Let(_, _)) || Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
|
||||
{
|
||||
let left = e.span.lo() + rustc_span::BytePos(5);
|
||||
let right = block.span.lo();
|
||||
(cond, UnusedDelimsCtx::WhileCond, true, Some(left), Some(right))
|
||||
|
@ -15,15 +15,8 @@ fn main() {
|
||||
while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses
|
||||
{{yield}}; //~ ERROR: unnecessary braces
|
||||
{( yield )}; //~ ERROR: unnecessary parentheses
|
||||
|
||||
// FIXME: Reduce duplicate warnings.
|
||||
// Perhaps we should tweak checks in `BlockRetValue`?
|
||||
while let Some(_) = {(yield)} {}
|
||||
//~^ ERROR: unnecessary braces
|
||||
//~| ERROR: unnecessary parentheses
|
||||
while let Some(_) = {{yield}} {}
|
||||
//~^ ERROR: unnecessary braces
|
||||
//~| ERROR: unnecessary braces
|
||||
while let Some(_) = {(yield)} {} //~ ERROR: unnecessary parentheses
|
||||
while let Some(_) = {{yield}} {} //~ ERROR: unnecessary braces
|
||||
|
||||
// FIXME: It'd be great if we could also warn them.
|
||||
((yield));
|
||||
|
@ -34,29 +34,17 @@ error: unnecessary parentheses around block return value
|
||||
LL | {( yield )};
|
||||
| ^^^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary braces around `let` scrutinee expression
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:29
|
||||
|
|
||||
LL | while let Some(_) = {(yield)} {}
|
||||
| ^^^^^^^^^ help: remove these braces
|
||||
|
||||
error: unnecessary parentheses around block return value
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:30
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:18:30
|
||||
|
|
||||
LL | while let Some(_) = {(yield)} {}
|
||||
| ^^^^^^^ help: remove these parentheses
|
||||
|
||||
error: unnecessary braces around `let` scrutinee expression
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:29
|
||||
|
|
||||
LL | while let Some(_) = {{yield}} {}
|
||||
| ^^^^^^^^^ help: remove these braces
|
||||
|
||||
error: unnecessary braces around block return value
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:30
|
||||
--> $DIR/issue-74883-unused-paren-baren-yield.rs:19:30
|
||||
|
|
||||
LL | while let Some(_) = {{yield}} {}
|
||||
| ^^^^^^^ help: remove these braces
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
// check-pass
|
||||
|
||||
#![deny(unused_braces)]
|
||||
|
||||
fn main() {
|
||||
let mut a = Some(3);
|
||||
// Shouldn't warn below `a`.
|
||||
while let Some(ref mut v) = {a} {
|
||||
a.as_mut().map(|a| std::mem::swap(a, v));
|
||||
break;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user