From 0ef4098a540f0e8b91f64e1a5670b4e3ff1f48f3 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Tue, 24 May 2022 23:41:34 +0000 Subject: Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros --- compiler/rustc_parse/src/parser/item.rs | 46 ++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 1d50ce767af..bf685aa8cad 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1775,30 +1775,34 @@ impl<'a> Parser<'a> { span, "macros that expand to items must be delimited with braces or followed by a semicolon", ); - if self.unclosed_delims.is_empty() { - let DelimSpan { open, close } = match args { - MacArgs::Empty | MacArgs::Eq(..) => unreachable!(), - MacArgs::Delimited(dspan, ..) => *dspan, - }; - err.multipart_suggestion( - "change the delimiters to curly braces", - vec![(open, "{".to_string()), (close, '}'.to_string())], - Applicability::MaybeIncorrect, - ); - } else { + // FIXME: This will make us not emit the help even for declarative + // macros within the same crate (that we can fix), which is sad. + if !span.from_expansion() { + if self.unclosed_delims.is_empty() { + let DelimSpan { open, close } = match args { + MacArgs::Empty | MacArgs::Eq(..) => unreachable!(), + MacArgs::Delimited(dspan, ..) => *dspan, + }; + err.multipart_suggestion( + "change the delimiters to curly braces", + vec![(open, "{".to_string()), (close, '}'.to_string())], + Applicability::MaybeIncorrect, + ); + } else { + err.span_suggestion( + span, + "change the delimiters to curly braces", + " { /* items */ }", + Applicability::HasPlaceholders, + ); + } err.span_suggestion( - span, - "change the delimiters to curly braces", - " { /* items */ }", - Applicability::HasPlaceholders, + span.shrink_to_hi(), + "add a semicolon", + ';', + Applicability::MaybeIncorrect, ); } - err.span_suggestion( - span.shrink_to_hi(), - "add a semicolon", - ';', - Applicability::MaybeIncorrect, - ); err.emit(); } -- cgit 1.4.1-3-g733a5