diff options
| author | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-03-09 13:48:40 +0900 |
|---|---|---|
| committer | Takayuki Maeda <takoyaki0316@gmail.com> | 2022-03-09 13:48:40 +0900 |
| commit | a34015c0d0c264e98b6753da4c5454433092c02b (patch) | |
| tree | fa3bb79e7f7373f295abdde31cd7c0488028e911 /compiler/rustc_parse/src/parser | |
| parent | 527b1f3c2fb478cf30c9b33e945da2adaf29b6e0 (diff) | |
| download | rust-a34015c0d0c264e98b6753da4c5454433092c02b.tar.gz rust-a34015c0d0c264e98b6753da4c5454433092c02b.zip | |
implement and use `diagnostic_snapshot`
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 7 | ||||
| -rw-r--r-- | 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<String, SpanSnippetError> { 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) => { |
