parse_enum_pattern_instead_of_identifier = expected identifier, found enum pattern
-parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `...`
- .suggestion = to omit remaining fields, use one fewer `.`
+parse_dot_dot_dot_for_remaining_fields = expected field pattern, found `{$token_str}`
+ .suggestion = to omit remaining fields, use `..`
parse_expected_comma_after_pattern_field = expected `,`
+use std::borrow::Cow;
+
use rustc_ast::token::Token;
use rustc_ast::{Path, Visibility};
use rustc_errors::{fluent, AddToDiagnostic, Applicability, EmissionGuarantee, IntoDiagnostic};
#[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)]
}
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);
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> {
--> $DIR/issue-46718-struct-pattern-dotdotdot.rs:11:55
|
LL | PersonalityInventory { expressivity: exp, ... } => exp
- | ^^^ help: to omit remaining fields, use one fewer `.`: `..`
+ | ^^^
+ |
+help: to omit remaining fields, use `..`
+ |
+LL | PersonalityInventory { expressivity: exp, .. } => exp
+ | ~~
error: aborting due to previous error
--> $DIR/issue-102806.rs:21:22
|
LL | let V3 { z: val, ... } = v;
- | ^^^ help: to omit remaining fields, use one fewer `.`: `..`
+ | ^^^
+ |
+help: to omit remaining fields, use `..`
+ |
+LL | let V3 { z: val, .. } = v;
+ | ~~
error[E0063]: missing fields `x` and `y` in initializer of `V3`
--> $DIR/issue-102806.rs:17:13
--> $DIR/issue-63135.rs:3:8
|
LL | fn i(n{...,f #
- | ^^^ help: to omit remaining fields, use one fewer `.`: `..`
+ | ^^^
+ |
+help: to omit remaining fields, use `..`
+ |
+LL | fn i(n{..,f #
+ | ~~
error: expected `}`, found `,`
--> $DIR/issue-63135.rs:3:11
let foo = Some(Foo::Other);
if let Some(Foo::Bar {_}) = foo {}
- //~^ ERROR expected identifier, found reserved identifier `_`
- //~| ERROR pattern does not mention field `bar` [E0027]
+ //~^ ERROR expected field pattern, found `_`
}
-error: expected identifier, found reserved identifier `_`
+error: expected field pattern, found `_`
--> $DIR/struct-enum-ignoring-field-with-underscore.rs:9:27
|
LL | if let Some(Foo::Bar {_}) = foo {}
- | ^ expected identifier, found reserved identifier
-
-error[E0027]: pattern does not mention field `bar`
- --> $DIR/struct-enum-ignoring-field-with-underscore.rs:9:17
- |
-LL | if let Some(Foo::Bar {_}) = foo {}
- | ^^^^^^^^^^^^ missing field `bar`
- |
-help: include the missing field in the pattern
+ | ^
|
-LL | if let Some(Foo::Bar {_, bar }) = foo {}
- | ~~~~~~~
-help: if you don't care about this missing field, you can explicitly ignore it
+help: to omit remaining fields, use `..`
|
-LL | if let Some(Foo::Bar {_, .. }) = foo {}
- | ~~~~~~
+LL | if let Some(Foo::Bar {..}) = foo {}
+ | ~~
-error: aborting due to 2 previous errors
+error: aborting due to previous error
-For more information about this error, try `rustc --explain E0027`.