diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-02 17:14:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-02 17:14:05 +0100 |
| commit | 8f47954742364b452716daff72bba976e18288e5 (patch) | |
| tree | 7e63fbd9a88c6bb7a6322f783a1afe2f711b7932 /compiler/rustc_parse/src | |
| parent | 97872b792c9dd6a9bc5c3f4e62a0bd5958b09cdc (diff) | |
| parent | 9dd5d3e8e421193be34fa822ab485de115174421 (diff) | |
| download | rust-8f47954742364b452716daff72bba976e18288e5.tar.gz rust-8f47954742364b452716daff72bba976e18288e5.zip | |
Rollup merge of #106919 - compiler-errors:underscore-typo-in-field-pat, r=jackh726
Recover `_` as `..` in field pattern
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 18 |
2 files changed, 15 insertions, 8 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 145611923ff..20da8ce5b6e 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1,3 +1,5 @@ +use std::borrow::Cow; + use rustc_ast::token::Token; use rustc_ast::{Path, Visibility}; use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic}; @@ -1802,8 +1804,9 @@ pub(crate) struct EnumPatternInsteadOfIdentifier { #[diag(parse_dot_dot_dot_for_remaining_fields)] pub(crate) struct DotDotDotForRemainingFields { #[primary_span] - #[suggestion(code = "..", applicability = "machine-applicable")] + #[suggestion(code = "..", style = "verbose", applicability = "machine-applicable")] pub span: Span, + pub token_str: Cow<'static, str>, } #[derive(Diagnostic)] diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index e75554ba124..0e8b549b438 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -962,12 +962,15 @@ impl<'a> Parser<'a> { } ate_comma = false; - if self.check(&token::DotDot) || self.token == token::DotDotDot { + if self.check(&token::DotDot) + || self.check_noexpect(&token::DotDotDot) + || self.check_keyword(kw::Underscore) + { etc = true; let mut etc_sp = self.token.span; - self.recover_one_fewer_dotdot(); - self.bump(); // `..` || `...` + self.recover_bad_dot_dot(); + self.bump(); // `..` || `...` || `_` if self.token == token::CloseDelim(Delimiter::Brace) { etc_span = Some(etc_sp); @@ -1060,14 +1063,15 @@ impl<'a> Parser<'a> { Ok((fields, etc)) } - /// Recover on `...` as if it were `..` to avoid further errors. + /// Recover on `...` or `_` as if it were `..` to avoid further errors. /// See issue #46718. - fn recover_one_fewer_dotdot(&self) { - if self.token != token::DotDotDot { + fn recover_bad_dot_dot(&self) { + if self.token == token::DotDot { return; } - self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span }); + let token_str = pprust::token_to_string(&self.token); + self.sess.emit_err(DotDotDotForRemainingFields { span: self.token.span, token_str }); } fn parse_pat_field(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, PatField> { |
