Correctly handle while-let-chains
This commit is contained in:
parent
9455259450
commit
a49368f00b
4 changed files with 51 additions and 4 deletions
|
@ -129,7 +129,7 @@ impl<'a> TokenTreesReader<'a> {
|
||||||
while parser.token != token::Eof {
|
while parser.token != token::Eof {
|
||||||
if let Err(diff_err) = parser.err_diff_marker() {
|
if let Err(diff_err) = parser.err_diff_marker() {
|
||||||
diff_errs.push(diff_err);
|
diff_errs.push(diff_err);
|
||||||
} else if parser.token.is_keyword(kw::If) {
|
} else if parser.is_keyword_ahead(0, &[kw::If, kw::While]) {
|
||||||
in_cond = true;
|
in_cond = true;
|
||||||
} else if matches!(
|
} else if matches!(
|
||||||
parser.token.kind,
|
parser.token.kind,
|
||||||
|
|
|
@ -1115,7 +1115,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.
|
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one.
|
||||||
fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool {
|
pub fn is_keyword_ahead(&self, dist: usize, kws: &[Symbol]) -> bool {
|
||||||
self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw)))
|
self.look_ahead(dist, |t| kws.iter().any(|&kw| t.is_keyword(kw)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,27 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn quux() {
|
||||||
|
while let () = ()
|
||||||
|
&& let () = () { //~ERROR: found a `{` in the middle of a let-chain
|
||||||
|
&& let () = ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foobar() {
|
||||||
|
while false {}
|
||||||
|
{
|
||||||
|
&& let () = ()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fubar() {
|
||||||
|
while false {
|
||||||
|
{
|
||||||
|
&& let () = ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn qux() {
|
fn qux() {
|
||||||
let foo = false;
|
let foo = false;
|
||||||
match foo {
|
match foo {
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
error: this file contains an unclosed delimiter
|
error: this file contains an unclosed delimiter
|
||||||
--> $DIR/brace-in-let-chain.rs:37:54
|
--> $DIR/brace-in-let-chain.rs:58:54
|
||||||
|
|
|
|
||||||
LL | fn main() {
|
LL | fn main() {
|
||||||
| - unclosed delimiter
|
| - unclosed delimiter
|
||||||
...
|
...
|
||||||
|
LL | fn quux() {
|
||||||
|
| - unclosed delimiter
|
||||||
|
...
|
||||||
|
LL | fn foobar() {
|
||||||
|
| - unclosed delimiter
|
||||||
|
...
|
||||||
|
LL | fn fubar() {
|
||||||
|
| - unclosed delimiter
|
||||||
|
...
|
||||||
LL | fn qux() {
|
LL | fn qux() {
|
||||||
| - unclosed delimiter
|
| - unclosed delimiter
|
||||||
...
|
...
|
||||||
|
@ -24,6 +33,23 @@ LL | }
|
||||||
LL | }
|
LL | }
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
|
error: found a `{` in the middle of a let-chain
|
||||||
|
--> $DIR/brace-in-let-chain.rs:14:24
|
||||||
|
|
|
||||||
|
LL | && let () = () {
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
note: you might have meant to continue the let-chain here
|
||||||
|
--> $DIR/brace-in-let-chain.rs:15:9
|
||||||
|
|
|
||||||
|
LL | && let () = ()
|
||||||
|
| ^^^^^^
|
||||||
|
help: consider removing this brace to parse the `let` as part of the same chain
|
||||||
|
|
|
||||||
|
LL - && let () = () {
|
||||||
|
LL + && let () = ()
|
||||||
|
|
|
||||||
|
|
||||||
error: found a `{` in the middle of a let-chain
|
error: found a `{` in the middle of a let-chain
|
||||||
--> $DIR/brace-in-let-chain.rs:6:24
|
--> $DIR/brace-in-let-chain.rs:6:24
|
||||||
|
|
|
|
||||||
|
@ -41,5 +67,5 @@ LL - && let () = () {
|
||||||
LL + && let () = ()
|
LL + && let () = ()
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue