diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-21 16:47:07 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-21 16:48:01 +1100 |
| commit | 0f490b040af82820e423a7e71e0e2e1f6ca7ab57 (patch) | |
| tree | 51e1a0678df173a482e283e176903ea3d3a0006e /compiler/rustc_parse/src | |
| parent | 76b04437be91069260c72a6d59d130a4e127a9a8 (diff) | |
| download | rust-0f490b040af82820e423a7e71e0e2e1f6ca7ab57.tar.gz rust-0f490b040af82820e423a7e71e0e2e1f6ca7ab57.zip | |
Avoid snapshotting the parser in `parse_path_inner`.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 7 |
4 files changed, 15 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 4b26100c46d..bbd73dec2e4 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -117,14 +117,13 @@ macro_rules! maybe_recover_from_interpolated_ty_qpath { ($self: expr, $allow_qpath_recovery: expr) => { if $allow_qpath_recovery && $self.may_recover() - && let Some(token::MetaVarKind::Ty) = $self.token.is_metavar_seq() + && let Some(mv_kind) = $self.token.is_metavar_seq() + && let token::MetaVarKind::Ty { .. } = mv_kind && $self.check_noexpect_past_close_delim(&token::PathSep) { // Reparse the type, then move to recovery. let ty = $self - .eat_metavar_seq(token::MetaVarKind::Ty, |this| { - this.parse_ty_no_question_mark_recover() - }) + .eat_metavar_seq(mv_kind, |this| this.parse_ty_no_question_mark_recover()) .expect("metavar seq ty"); return $self.maybe_recover_from_bad_qpath_stage_2($self.prev_token.span, ty); diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index e9cf8f1bbba..f202f85752e 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -30,7 +30,7 @@ impl<'a> Parser<'a> { MetaVarKind::Stmt | MetaVarKind::Pat(_) | MetaVarKind::Expr { .. } - | MetaVarKind::Ty + | MetaVarKind::Ty { .. } | MetaVarKind::Literal // `true`, `false` | MetaVarKind::Meta | MetaVarKind::Path => true, @@ -108,7 +108,7 @@ impl<'a> Parser<'a> { | MetaVarKind::Literal => true, MetaVarKind::Item | MetaVarKind::Pat(_) - | MetaVarKind::Ty + | MetaVarKind::Ty { .. } | MetaVarKind::Meta | MetaVarKind::Path | MetaVarKind::Vis => false, diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index b68eb9c99f5..c24305ea9a8 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -196,15 +196,12 @@ impl<'a> Parser<'a> { maybe_whole!(self, NtPath, |path| reject_generics_if_mod_style(self, path.into_inner())); - if let Some(MetaVarKind::Ty) = self.token.is_metavar_seq() { - let mut snapshot = self.create_snapshot_for_diagnostic(); - let ty = snapshot - .eat_metavar_seq(MetaVarKind::Ty, |this| this.parse_ty_no_question_mark_recover()) - .expect("metavar seq ty"); - if let ast::TyKind::Path(None, path) = ty.into_inner().kind { - self.restore_snapshot(snapshot); - return Ok(reject_generics_if_mod_style(self, path)); - } + // If we have a `ty` metavar in the form of a path, reparse it directly as a path, instead + // of reparsing it as a `ty` and then extracting the path. + if let Some(path) = self.eat_metavar_seq(MetaVarKind::Ty { is_path: true }, |this| { + this.parse_path(PathStyle::Type) + }) { + return Ok(reject_generics_if_mod_style(self, path)); } let lo = self.token.span; diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index c78c7bff9b5..18af0a1c79a 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -249,9 +249,10 @@ impl<'a> Parser<'a> { let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); - if let Some(ty) = - self.eat_metavar_seq(MetaVarKind::Ty, |this| this.parse_ty_no_question_mark_recover()) - { + if let Some(ty) = self.eat_metavar_seq_with_matcher( + |mv_kind| matches!(mv_kind, MetaVarKind::Ty { .. }), + |this| this.parse_ty_no_question_mark_recover(), + ) { return Ok(ty); } |
