Skip to content

Commit 2e7ba78

Browse files
committed
Recover strictness for yield
1 parent 86d0b9c commit 2e7ba78

File tree

3 files changed

+60
-9
lines changed

3 files changed

+60
-9
lines changed

src/librustc_lint/unused.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,9 @@ trait UnusedDelimLint {
422422
lhs_needs_parens
423423
|| (followed_by_block
424424
&& match inner.kind {
425-
ExprKind::Ret(_) | ExprKind::Break(..) => true,
425+
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true,
426426
_ => parser::contains_exterior_struct_lit(&inner),
427427
})
428-
|| if let ExprKind::Yield(..) = inner.kind { true } else { false }
429428
}
430429

431430
fn emit_unused_delims_expr(

src/test/ui/lint/issue-74883-unused-paren-baren-yield.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,25 @@ fn main() {
99
let mut x = |_| {
1010
while let Some(_) = (yield) {}
1111
while let Some(_) = {yield} {}
12+
1213
// Only warn these cases
1314
while let Some(_) = ({yield}) {} //~ ERROR: unnecessary parentheses
14-
while let Some(_) = {(yield)} {} //~ ERROR: unnecessary braces
15+
while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses
16+
{{yield}}; //~ ERROR: unnecessary braces
17+
{( yield )}; //~ ERROR: unnecessary parentheses
18+
19+
// FIXME: Reduce duplicate warnings.
20+
// Perhaps we should tweak checks in `BlockRetValue`?
21+
while let Some(_) = {(yield)} {}
22+
//~^ ERROR: unnecessary braces
23+
//~| ERROR: unnecessary parentheses
24+
while let Some(_) = {{yield}} {}
25+
//~^ ERROR: unnecessary braces
26+
//~| ERROR: unnecessary braces
27+
28+
// FIXME: It'd be great if we could also warn them.
29+
((yield));
30+
({ yield });
1531
};
1632
let _ = Pin::new(&mut x).resume(Some(5));
1733
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unnecessary parentheses around `let` scrutinee expression
2-
--> $DIR/issue-74883-unused-paren-baren-yield.rs:13:29
2+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29
33
|
44
LL | while let Some(_) = ({yield}) {}
55
| ^^^^^^^^^ help: remove these parentheses
@@ -10,17 +10,53 @@ note: the lint level is defined here
1010
LL | #![deny(unused_braces, unused_parens)]
1111
| ^^^^^^^^^^^^^
1212

13-
error: unnecessary braces around `let` scrutinee expression
14-
--> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29
13+
error: unnecessary parentheses around `let` scrutinee expression
14+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29
1515
|
16-
LL | while let Some(_) = {(yield)} {}
17-
| ^^^^^^^^^ help: remove these braces
16+
LL | while let Some(_) = ((yield)) {}
17+
| ^^^^^^^^^ help: remove these parentheses
18+
19+
error: unnecessary braces around block return value
20+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:16:10
21+
|
22+
LL | {{yield}};
23+
| ^^^^^^^ help: remove these braces
1824
|
1925
note: the lint level is defined here
2026
--> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9
2127
|
2228
LL | #![deny(unused_braces, unused_parens)]
2329
| ^^^^^^^^^^^^^
2430

25-
error: aborting due to 2 previous errors
31+
error: unnecessary parentheses around block return value
32+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:17:10
33+
|
34+
LL | {( yield )};
35+
| ^^^^^^^^^ help: remove these parentheses
36+
37+
error: unnecessary braces around `let` scrutinee expression
38+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:29
39+
|
40+
LL | while let Some(_) = {(yield)} {}
41+
| ^^^^^^^^^ help: remove these braces
42+
43+
error: unnecessary parentheses around block return value
44+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:30
45+
|
46+
LL | while let Some(_) = {(yield)} {}
47+
| ^^^^^^^ help: remove these parentheses
48+
49+
error: unnecessary braces around `let` scrutinee expression
50+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:29
51+
|
52+
LL | while let Some(_) = {{yield}} {}
53+
| ^^^^^^^^^ help: remove these braces
54+
55+
error: unnecessary braces around block return value
56+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:30
57+
|
58+
LL | while let Some(_) = {{yield}} {}
59+
| ^^^^^^^ help: remove these braces
60+
61+
error: aborting due to 8 previous errors
2662

0 commit comments

Comments
 (0)