Skip to content

Commit e7bb090

Browse files
authored
Rollup merge of #124930 - compiler-errors:consume-arg, r=petrochenkov
Make sure we consume a generic arg when checking mistyped turbofish When recovering un-turbofish-ed args in expr position (e.g. `let x = a<T, U>();` in `check_mistyped_turbofish_with_multiple_type_params`, we used `parse_seq_to_before_end` to parse the fake generic args; however, it used `parse_generic_arg` which *optionally* parses a generic arg. If it doesn't end up parsing an arg, it returns `Ok(None)` and consumes no tokens. If we don't find a delimiter after this (`,`), we try parsing *another* element. In this case, we just infinitely loop looking for a subsequent element. We can fix this by making sure that we either parse a generic arg or error in `parse_seq_to_before_end`'s callback. Fixes #124897
2 parents d8bf3fd + dbdef68 commit e7bb090

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,11 @@ impl<'a> Parser<'a> {
12231223
let x = self.parse_seq_to_before_end(
12241224
&token::Gt,
12251225
SeqSep::trailing_allowed(token::Comma),
1226-
|p| p.parse_generic_arg(None),
1226+
|p| match p.parse_generic_arg(None)? {
1227+
Some(arg) => Ok(arg),
1228+
// If we didn't eat a generic arg, then we should error.
1229+
None => p.unexpected_any(),
1230+
},
12271231
);
12281232
match x {
12291233
Ok((_, _, Recovered::No)) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() {
2+
let x = Tr<A, A:>;
3+
//~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,`
2+
--> $DIR/turbofish-arg-with-stray-colon.rs:2:17
3+
|
4+
LL | let x = Tr<A, A:>;
5+
| ^ expected one of 8 possible tokens
6+
|
7+
= note: type ascription syntax has been removed, see issue #101728 <https://github.com/rust-lang/rust/issues/101728>
8+
help: maybe write a path separator here
9+
|
10+
LL | let x = Tr<A, A::>;
11+
| ~~
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)