Skip to content

Commit f49601d

Browse files
committed
not suggest if span originates in a derive-macro's expansion
1 parent f50da2e commit f49601d

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

compiler/rustc_parse/src/parser/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ impl<'a> Parser<'a> {
12311231
}
12321232
let enum_field_start_span = this.token.span;
12331233
let ident = this.parse_field_ident("enum", vlo)?;
1234-
if this.token.kind == token::Colon {
1234+
if this.token.kind == token::Colon && !start_span.in_derive_expansion() {
12351235
let snapshot = this.clone();
12361236
this.bump();
12371237
match this.parse_ty() {
@@ -1612,7 +1612,7 @@ impl<'a> Parser<'a> {
16121612
{
16131613
let snapshot = self.clone();
16141614
if let Err(err) = self.parse_ty() {
1615-
if let Some(span) = start_span {
1615+
if let Some(span) = start_span && !span.in_derive_expansion() {
16161616
error.span_suggestion_verbose(
16171617
span,
16181618
"consider using `enum` instead of `struct`",

src/test/ui/proc-macro/derive-bad.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ LL | #[derive(A)]
55
| ^ expected `:`
66
|
77
= note: this error originates in the derive macro `A` (in Nightly builds, run with -Z macro-backtrace for more info)
8-
help: consider using `enum` instead of `struct`
9-
|
10-
LL | #[derive(enum)]
11-
| ~~~~
128

139
error: proc-macro derive produced unparseable tokens
1410
--> $DIR/derive-bad.rs:6:10

0 commit comments

Comments
 (0)