mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
Suggest fix for ; within let-chains
This commit is contained in:
parent
d8dbf7ca0e
commit
5693a34db2
|
@ -2441,10 +2441,26 @@ fn parse_if_after_cond(&mut self, lo: Span, mut cond: P<Expr>) -> PResult<'a, P<
|
||||||
self.error_on_extra_if(&cond)?;
|
self.error_on_extra_if(&cond)?;
|
||||||
// Parse block, which will always fail, but we can add a nice note to the error
|
// Parse block, which will always fail, but we can add a nice note to the error
|
||||||
self.parse_block().map_err(|mut err| {
|
self.parse_block().map_err(|mut err| {
|
||||||
err.span_note(
|
if self.prev_token == token::Semi
|
||||||
cond_span,
|
&& self.token == token::AndAnd
|
||||||
"the `if` expression is missing a block after this condition",
|
&& let maybe_let = self.look_ahead(1, |t| t.clone())
|
||||||
);
|
&& maybe_let.is_keyword(kw::Let)
|
||||||
|
{
|
||||||
|
err.span_suggestion(
|
||||||
|
self.prev_token.span,
|
||||||
|
"consider removing this semicolon to parse the `let` as part of the same chain",
|
||||||
|
"",
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
).span_note(
|
||||||
|
self.token.span.to(maybe_let.span),
|
||||||
|
"you likely meant to continue parsing the let-chain starting here",
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
err.span_note(
|
||||||
|
cond_span,
|
||||||
|
"the `if` expression is missing a block after this condition",
|
||||||
|
);
|
||||||
|
}
|
||||||
err
|
err
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
|
|
27
tests/ui/parser/semi-in-let-chain.rs
Normal file
27
tests/ui/parser/semi-in-let-chain.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
// Issue #117720
|
||||||
|
|
||||||
|
#![feature(let_chains)]
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if let () = ()
|
||||||
|
&& let () = (); //~ERROR
|
||||||
|
&& let () = ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
if let () = ()
|
||||||
|
&& () == (); //~ERROR
|
||||||
|
&& 1 < 0
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar() {
|
||||||
|
if let () = ()
|
||||||
|
&& () == (); //~ERROR
|
||||||
|
&& let () = ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
50
tests/ui/parser/semi-in-let-chain.stderr
Normal file
50
tests/ui/parser/semi-in-let-chain.stderr
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
error: expected `{`, found `;`
|
||||||
|
--> $DIR/semi-in-let-chain.rs:7:23
|
||||||
|
|
|
||||||
|
LL | && let () = ();
|
||||||
|
| ^ expected `{`
|
||||||
|
|
|
||||||
|
note: you likely meant to continue parsing the let-chain starting here
|
||||||
|
--> $DIR/semi-in-let-chain.rs:8:9
|
||||||
|
|
|
||||||
|
LL | && let () = ()
|
||||||
|
| ^^^^^^
|
||||||
|
help: consider removing this semicolon to parse the `let` as part of the same chain
|
||||||
|
|
|
||||||
|
LL - && let () = ();
|
||||||
|
LL + && let () = ()
|
||||||
|
|
|
||||||
|
|
||||||
|
error: expected `{`, found `;`
|
||||||
|
--> $DIR/semi-in-let-chain.rs:15:20
|
||||||
|
|
|
||||||
|
LL | && () == ();
|
||||||
|
| ^ expected `{`
|
||||||
|
|
|
||||||
|
note: the `if` expression is missing a block after this condition
|
||||||
|
--> $DIR/semi-in-let-chain.rs:14:8
|
||||||
|
|
|
||||||
|
LL | if let () = ()
|
||||||
|
| ________^
|
||||||
|
LL | | && () == ();
|
||||||
|
| |___________________^
|
||||||
|
|
||||||
|
error: expected `{`, found `;`
|
||||||
|
--> $DIR/semi-in-let-chain.rs:23:20
|
||||||
|
|
|
||||||
|
LL | && () == ();
|
||||||
|
| ^ expected `{`
|
||||||
|
|
|
||||||
|
note: you likely meant to continue parsing the let-chain starting here
|
||||||
|
--> $DIR/semi-in-let-chain.rs:24:9
|
||||||
|
|
|
||||||
|
LL | && let () = ()
|
||||||
|
| ^^^^^^
|
||||||
|
help: consider removing this semicolon to parse the `let` as part of the same chain
|
||||||
|
|
|
||||||
|
LL - && () == ();
|
||||||
|
LL + && () == ()
|
||||||
|
|
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
Loading…
Reference in a new issue