about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-06-16 23:50:20 +0000
committerbors <bors@rust-lang.org>2022-06-16 23:50:20 +0000
commit349bda2051e94b7aefb33d6541f48f561bf06dbc (patch)
tree53b5320c033a44c0e0ed2f23b2ad5b194f083d2c /compiler/rustc_parse/src/parser
parentcacc75c82ebe15cf63d31034fcf7f1016cddf0e2 (diff)
parent6ac93185f4daacacb537d5b61e900eb9d58edcd1 (diff)
downloadrust-349bda2051e94b7aefb33d6541f48f561bf06dbc.tar.gz
rust-349bda2051e94b7aefb33d6541f48f561bf06dbc.zip
Auto merge of #98181 - JohnTitor:rollup-65ztwnz, r=JohnTitor
Rollup of 5 pull requests

Successful merges:

 - #97377 (Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros)
 - #97675 (Make `std::mem::needs_drop` accept `?Sized`)
 - #98118 (Test NLL fix of bad lifetime inference for reference captured in closure.)
 - #98166 (Add rustdoc-json regression test for #98009)
 - #98169 (Keyword docs: Link to wikipedia article for dynamic dispatch)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/item.rs46
1 files changed, 25 insertions, 21 deletions
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();
     }