about summary refs log tree commit diff
path: root/compiler/rustc_parse
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-05-11 01:15:10 +0100
committerGitHub <noreply@github.com>2024-05-11 01:15:10 +0100
commite7bb090d0ae67f355409213c800a73533b56301e (patch)
tree4c2140c7a13095f420ccfda666c1a345edcb4b28 /compiler/rustc_parse
parentd8bf3fd58444c43c123a3edd3138feeb15afea77 (diff)
parentdbdef68ddf0b8200954c81264400ef271a5f0194 (diff)
downloadrust-e7bb090d0ae67f355409213c800a73533b56301e.tar.gz
rust-e7bb090d0ae67f355409213c800a73533b56301e.zip
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
Diffstat (limited to 'compiler/rustc_parse')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index 995803f9cd0..50698dbf9c1 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -1223,7 +1223,11 @@ impl<'a> Parser<'a> {
             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)) => {