Suggest fix for ; within let-chains · rust-lang/rust@5693a34 (original) (raw)
File tree
3 files changed
lines changed
- compiler/rustc_parse/src/parser
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2441,10 +2441,26 @@ impl<'a> Parser<'a> { | ||
2441 | 2441 | self.error_on_extra_if(&cond)?; |
2442 | 2442 | // Parse block, which will always fail, but we can add a nice note to the error |
2443 | 2443 | self.parse_block().map_err(|mut err |
2444 | - err.span_note( | |
2445 | - cond_span, | |
2446 | -"the `if` expression is missing a block after this condition", | |
2447 | -); | |
2444 | +if self.prev_token == token::Semi | |
2445 | + && self.token == token::AndAnd | |
2446 | + && let maybe_let = self.look_ahead(1, |t | |
2447 | + && maybe_let.is_keyword(kw::Let) | |
2448 | +{ | |
2449 | + err.span_suggestion( | |
2450 | +self.prev_token.span, | |
2451 | +"consider removing this semicolon to parse the `let` as part of the same chain", | |
2452 | +"", | |
2453 | +Applicability::MachineApplicable, | |
2454 | +).span_note( | |
2455 | +self.token.span.to(maybe_let.span), | |
2456 | +"you likely meant to continue parsing the let-chain starting here", | |
2457 | +); | |
2458 | +} else { | |
2459 | + err.span_note( | |
2460 | + cond_span, | |
2461 | +"the `if` expression is missing a block after this condition", | |
2462 | +); | |
2463 | +} | |
2448 | 2464 | err |
2449 | 2465 | })? |
2450 | 2466 | } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
1 | +// Issue #117720 | |
2 | + | |
3 | +#![feature(let_chains)] | |
4 | + | |
5 | +fn main() { | |
6 | +if let () = () | |
7 | + && let () = (); //~ERROR | |
8 | + && let () = () | |
9 | +{ | |
10 | +} | |
11 | +} | |
12 | + | |
13 | +fn foo() { | |
14 | +if let () = () | |
15 | + && () == (); //~ERROR | |
16 | + && 1 < 0 | |
17 | +{ | |
18 | +} | |
19 | +} | |
20 | + | |
21 | +fn bar() { | |
22 | +if let () = () | |
23 | + && () == (); //~ERROR | |
24 | + && let () = () | |
25 | +{ | |
26 | +} | |
27 | +} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
1 | +error: expected `{`, found `;` | |
2 | + --> $DIR/semi-in-let-chain.rs:7:23 | |
3 | + | | |
4 | +LL | && let () = (); | |
5 | + | ^ expected `{` | |
6 | + | | |
7 | +note: you likely meant to continue parsing the let-chain starting here | |
8 | + --> $DIR/semi-in-let-chain.rs:8:9 | |
9 | + | | |
10 | +LL | && let () = () | |
11 | + | ^^^^^^ | |
12 | +help: consider removing this semicolon to parse the `let` as part of the same chain | |
13 | + | | |
14 | +LL - && let () = (); | |
15 | +LL + && let () = () | |
16 | + | | |
17 | + | |
18 | +error: expected `{`, found `;` | |
19 | + --> $DIR/semi-in-let-chain.rs:15:20 | |
20 | + | | |
21 | +LL | && () == (); | |
22 | + | ^ expected `{` | |
23 | + | | |
24 | +note: the `if` expression is missing a block after this condition | |
25 | + --> $DIR/semi-in-let-chain.rs:14:8 | |
26 | + | | |
27 | +LL | if let () = () | |
28 | + | ________^ | |
29 | +LL | | |
30 | + | | |
31 | + | |
32 | +error: expected `{`, found `;` | |
33 | + --> $DIR/semi-in-let-chain.rs:23:20 | |
34 | + | | |
35 | +LL | && () == (); | |
36 | + | ^ expected `{` | |
37 | + | | |
38 | +note: you likely meant to continue parsing the let-chain starting here | |
39 | + --> $DIR/semi-in-let-chain.rs:24:9 | |
40 | + | | |
41 | +LL | && let () = () | |
42 | + | ^^^^^^ | |
43 | +help: consider removing this semicolon to parse the `let` as part of the same chain | |
44 | + | | |
45 | +LL - && () == (); | |
46 | +LL + && () == () | |
47 | + | | |
48 | + | |
49 | +error: aborting due to 3 previous errors | |
50 | + |