From f49601de82809f3f0858bfada642dbfc0a14ec6c Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 21 Mar 2022 00:29:27 +0900 Subject: [PATCH] not suggest if `span` originates in a derive-macro's expansion --- compiler/rustc_parse/src/parser/item.rs | 4 ++-- src/test/ui/proc-macro/derive-bad.stderr | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 6c8f9015686a1..33b3d4bf093fa 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1231,7 +1231,7 @@ impl<'a> Parser<'a> { } let enum_field_start_span = this.token.span; let ident = this.parse_field_ident("enum", vlo)?; - if this.token.kind == token::Colon { + if this.token.kind == token::Colon && !start_span.in_derive_expansion() { let snapshot = this.clone(); this.bump(); match this.parse_ty() { @@ -1612,7 +1612,7 @@ impl<'a> Parser<'a> { { let snapshot = self.clone(); if let Err(err) = self.parse_ty() { - if let Some(span) = start_span { + if let Some(span) = start_span && !span.in_derive_expansion() { error.span_suggestion_verbose( span, "consider using `enum` instead of `struct`", diff --git a/src/test/ui/proc-macro/derive-bad.stderr b/src/test/ui/proc-macro/derive-bad.stderr index 981310e4013ce..ae48141fb3133 100644 --- a/src/test/ui/proc-macro/derive-bad.stderr +++ b/src/test/ui/proc-macro/derive-bad.stderr @@ -5,10 +5,6 @@ LL | #[derive(A)] | ^ expected `:` | = note: this error originates in the derive macro `A` (in Nightly builds, run with -Z macro-backtrace for more info) -help: consider using `enum` instead of `struct` - | -LL | #[derive(enum)] - | ~~~~ error: proc-macro derive produced unparseable tokens --> $DIR/derive-bad.rs:6:10