From a34015c0d0c264e98b6753da4c5454433092c02b Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 9 Mar 2022 13:48:40 +0900 Subject: [PATCH] implement and use `diagnostic_snapshot` --- compiler/rustc_parse/src/parser/diagnostics.rs | 7 +++++++ compiler/rustc_parse/src/parser/path.rs | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 40daf4eb28f..94805f4eb8b 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -179,6 +179,13 @@ impl<'a> Parser<'a> { &self.sess.span_diagnostic } + pub(super) fn diagnostic_snapshot(&self) -> Self { + let mut snapshot = self.clone(); + // initialize unclosed_delims to avoid duplicate errors. + snapshot.unclosed_delims = vec![]; + snapshot + } + pub(super) fn span_to_snippet(&self, span: Span) -> Result { self.sess.source_map().span_to_snippet(span) } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 750d7cce0c0..f300b9c5ae4 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -625,8 +625,7 @@ impl<'a> Parser<'a> { } else if self.check_type() { // Parse type argument. let is_const_fn = self.look_ahead(1, |t| t.kind == token::OpenDelim(token::Paren)); - let mut snapshot = self.clone(); - snapshot.unclosed_delims = vec![]; + let mut snapshot = self.diagnostic_snapshot(); match self.parse_ty() { Ok(ty) => GenericArg::Type(ty), Err(err) => {