diff options
| author | Chayim Refael Friedman <chayimfr@gmail.com> | 2022-05-24 23:41:34 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-16 02:19:31 +0000 |
| commit | 0ef4098a540f0e8b91f64e1a5670b4e3ff1f48f3 (patch) | |
| tree | 83c7c2bfc3a7e460dc67a9e52cdd255aa0c1ed2d /compiler/rustc_parse/src/parser | |
| parent | b31f9cc22bcd720b37ddf927afe378108a5b9a54 (diff) | |
| download | rust-0ef4098a540f0e8b91f64e1a5670b4e3ff1f48f3.tar.gz rust-0ef4098a540f0e8b91f64e1a5670b4e3ff1f48f3.zip | |
Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 46 |
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(); } |
