From 531193853142a2564f1c667c9e8ca96c524a380b Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Mon, 9 Jan 2023 05:29:54 +0000 Subject: Detect struct literal needing parentheses Fix #82051. --- compiler/rustc_parse/src/errors.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'compiler/rustc_parse/src/errors.rs') diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index 574591529f3..19eeb069a25 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -970,6 +970,24 @@ pub(crate) struct StructLiteralBodyWithoutPathSugg { pub after: Span, } +#[derive(Diagnostic)] +#[diag(parse_struct_literal_needing_parens)] +pub(crate) struct StructLiteralNeedingParens { + #[primary_span] + pub span: Span, + #[subdiagnostic] + pub sugg: StructLiteralNeedingParensSugg, +} + +#[derive(Subdiagnostic)] +#[multipart_suggestion(suggestion, applicability = "machine-applicable")] +pub(crate) struct StructLiteralNeedingParensSugg { + #[suggestion_part(code = "(")] + pub before: Span, + #[suggestion_part(code = ")")] + pub after: Span, +} + #[derive(Diagnostic)] #[diag(parse_unmatched_angle_brackets)] pub(crate) struct UnmatchedAngleBrackets { -- cgit 1.4.1-3-g733a5