]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_parse/src/parser/item.rs
Rollup merge of #97249 - GuillaumeGomez:details-summary-fixes, r=notriddle
[rust.git] / compiler / rustc_parse / src / parser / item.rs
index 1d50ce767afb104f7ee935aab94378d72d091f96..bf685aa8cadc34005755d89ccade55924b2b79f6 100644 (file)
@@ -1775,30 +1775,34 @@ fn report_invalid_macro_expansion_item(&self, args: &MacArgs) {
             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();
     }