diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index f256dbf4360..ccf3b82ff7a 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1224,7 +1224,11 @@ pub(super) fn check_mistyped_turbofish_with_multiple_type_params( let x = self.parse_seq_to_before_end( &token::Gt, SeqSep::trailing_allowed(token::Comma), - |p| p.parse_generic_arg(None), + |p| match p.parse_generic_arg(None)? { + Some(arg) => Ok(arg), + // If we didn't eat a generic arg, then we should error. + None => p.unexpected_any(), + }, ); match x { Ok((_, _, Recovered::No)) => { diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs new file mode 100644 index 00000000000..32125211a91 --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.rs @@ -0,0 +1,6 @@ +fn foo() { + let x = Tr; + //~^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` +} + +fn main() {} diff --git a/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr new file mode 100644 index 00000000000..551b2e3ff09 --- /dev/null +++ b/tests/ui/parser/recover/turbofish-arg-with-stray-colon.stderr @@ -0,0 +1,14 @@ +error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `,` + --> $DIR/turbofish-arg-with-stray-colon.rs:2:17 + | +LL | let x = Tr; + | ^ expected one of 8 possible tokens + | + = note: type ascription syntax has been removed, see issue #101728 +help: maybe write a path separator here + | +LL | let x = Tr; + | ~~ + +error: aborting due to 1 previous error +