diff options
| author | yukang <moorekang@gmail.com> | 2022-10-13 23:27:17 +0800 |
|---|---|---|
| committer | yukang <moorekang@gmail.com> | 2022-11-04 10:35:36 +0800 |
| commit | 1e25882944aabcf0c871182b887cd4ffe9c7b330 (patch) | |
| tree | 2bef772d7d5d88173b8eddedca32592753431a6e /compiler/rustc_parse/src | |
| parent | 6718ea1cff98da785c10079cac1c1ecc30c12d52 (diff) | |
| download | rust-1e25882944aabcf0c871182b887cd4ffe9c7b330.tar.gz rust-1e25882944aabcf0c871182b887cd4ffe9c7b330.zip | |
fix #102806, suggest use .. to fill in the rest of the fields of Struct
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 21 |
2 files changed, 27 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index dc204902842..b02bd664533 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -369,6 +369,15 @@ pub(crate) struct MissingSemicolonBeforeArray { } #[derive(Diagnostic)] +#[diag(parser_expect_dotdot_not_dotdotdot)] +pub(crate) struct MissingDotDot { + #[primary_span] + pub token_span: Span, + #[suggestion_verbose(applicability = "maybe-incorrect", code = "..")] + pub sugg_span: Span, +} + +#[derive(Diagnostic)] #[diag(parser_invalid_block_macro_segment)] pub(crate) struct InvalidBlockMacroSegment { #[primary_span] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 0eb633f6416..7de025e7860 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -20,9 +20,9 @@ use crate::errors::{ InvalidNumLiteralSuffix, LabeledLoopInBreak, LeadingPlusNotSupported, LeftArrowOperator, LifetimeInBorrowExpression, MacroInvocationWithQualifiedPath, MalformedLoopLabel, MatchArmBodyWithoutBraces, MatchArmBodyWithoutBracesSugg, MissingCommaAfterMatchArm, - MissingInInForLoop, MissingInInForLoopSub, MissingSemicolonBeforeArray, NoFieldsForFnCall, - NotAsNegationOperator, NotAsNegationOperatorSub, OctalFloatLiteralNotSupported, - OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields, + MissingDotDot, MissingInInForLoop, MissingInInForLoopSub, MissingSemicolonBeforeArray, + NoFieldsForFnCall, NotAsNegationOperator, NotAsNegationOperatorSub, + OctalFloatLiteralNotSupported, OuterAttributeNotAllowedOnIfElse, ParenthesesWithStructFields, RequireColonAfterLabeledExpression, ShiftInterpretedAsGeneric, StructLiteralNotAllowedHere, StructLiteralNotAllowedHereSugg, TildeAsUnaryOperator, UnexpectedTokenAfterLabel, UnexpectedTokenAfterLabelSugg, WrapExpressionInParentheses, @@ -2897,6 +2897,21 @@ impl<'a> Parser<'a> { } self.recover_struct_comma_after_dotdot(exp_span); break; + } else if self.token == token::DotDotDot { + // suggest `..v` instead of `...v` + let snapshot = self.create_snapshot_for_diagnostic(); + let span = self.token.span; + self.bump(); + match self.parse_expr() { + Ok(_p) => { + self.sess.emit_err(MissingDotDot { token_span: span, sugg_span: span }); + break; + } + Err(inner_err) => { + inner_err.cancel(); + self.restore_snapshot(snapshot); + } + } } let recovery_field = self.find_struct_error_after_field_looking_code(); |
