Skip to content

Commit db3e10f

Browse files
authored
Rollup merge of #75031 - JohnTitor:unused-parens-braces-yield, r=lcnr
Do not trigger `unused_{braces,parens}` lints with `yield` Fixes #74883 r? @lcnr
2 parents 1b350ec + 2e7ba78 commit db3e10f

File tree

3 files changed

+96
-1
lines changed

3 files changed

+96
-1
lines changed

src/librustc_lint/unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ 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
})
428428
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(generator_trait)]
2+
#![feature(generators)]
3+
#![deny(unused_braces, unused_parens)]
4+
5+
use std::ops::Generator;
6+
use std::pin::Pin;
7+
8+
fn main() {
9+
let mut x = |_| {
10+
while let Some(_) = (yield) {}
11+
while let Some(_) = {yield} {}
12+
13+
// Only warn these cases
14+
while let Some(_) = ({yield}) {} //~ ERROR: unnecessary parentheses
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 });
31+
};
32+
let _ = Pin::new(&mut x).resume(Some(5));
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: unnecessary parentheses around `let` scrutinee expression
2+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:14:29
3+
|
4+
LL | while let Some(_) = ({yield}) {}
5+
| ^^^^^^^^^ help: remove these parentheses
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:3:24
9+
|
10+
LL | #![deny(unused_braces, unused_parens)]
11+
| ^^^^^^^^^^^^^
12+
13+
error: unnecessary parentheses around `let` scrutinee expression
14+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:15:29
15+
|
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
24+
|
25+
note: the lint level is defined here
26+
--> $DIR/issue-74883-unused-paren-baren-yield.rs:3:9
27+
|
28+
LL | #![deny(unused_braces, unused_parens)]
29+
| ^^^^^^^^^^^^^
30+
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
62+

0 commit comments

Comments
 (0)