diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-07-10 22:14:52 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2021-07-10 23:03:35 +0300 |
| commit | 28f4dba4388c81a77b656c624e796f5b5c589ba0 (patch) | |
| tree | 6c8ba083e4d0b1d915c345981c56532be4e8cafb | |
| parent | a31431fce770ff90a347fd6114ac294e4568cbd8 (diff) | |
| download | rust-28f4dba4388c81a77b656c624e796f5b5c589ba0.tar.gz rust-28f4dba4388c81a77b656c624e796f5b5c589ba0.zip | |
rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
19 files changed, 37 insertions, 118 deletions
diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index d3f92bf3047..fd024a8ecfa 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -309,9 +309,7 @@ pub trait Emitter { // are some which do actually involve macros. ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None, - ExpnKind::Macro { kind: macro_kind, name, proc_macro: _ } => { - Some((macro_kind, name)) - } + ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)), } }); @@ -372,19 +370,10 @@ pub trait Emitter { new_labels .push((trace.call_site, "in the inlined copy of this code".to_string())); } else if always_backtrace { - let proc_macro = if let ExpnKind::Macro { kind: _, name: _, proc_macro: true } = - trace.kind - { - "procedural macro " - } else { - "" - }; - new_labels.push(( trace.def_site, format!( - "in this expansion of {}`{}`{}", - proc_macro, + "in this expansion of `{}`{}", trace.kind.descr(), if macro_backtrace.len() > 1 { // if macro_backtrace.len() == 1 it'll be @@ -410,11 +399,7 @@ pub trait Emitter { // and it needs an "in this macro invocation" label to match that. let redundant_span = trace.call_site.contains(sp); - if !redundant_span - && matches!( - trace.kind, - ExpnKind::Macro { kind: MacroKind::Bang, name: _, proc_macro: _ } - ) + if !redundant_span && matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _)) || always_backtrace { new_labels.push(( diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 67d71ce48ff..b3e52502b07 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -811,16 +811,8 @@ impl SyntaxExtension { macro_def_id: Option<DefId>, parent_module: Option<DefId>, ) -> ExpnData { - use SyntaxExtensionKind::*; - let proc_macro = match self.kind { - // User-defined proc macro - Bang(..) | Attr(..) | Derive(..) => true, - // Consider everthing else to be not a proc - // macro for diagnostic purposes - LegacyBang(..) | LegacyAttr(..) | NonMacroAttr { .. } | LegacyDerive(..) => false, - }; ExpnData::new( - ExpnKind::Macro { kind: self.macro_kind(), name: descr, proc_macro }, + ExpnKind::Macro(self.macro_kind(), descr), parent, call_site, self.span, diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 1d73002710d..81b42055530 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -812,7 +812,7 @@ fn ident_name_compatibility_hack( rustc: &mut Rustc<'_>, ) -> Option<(rustc_span::symbol::Ident, bool)> { if let NtIdent(ident, is_raw) = nt { - if let ExpnKind::Macro { name: macro_name, .. } = orig_span.ctxt().outer_expn_data().kind { + if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind { let source_map = rustc.sess.source_map(); let filename = source_map.span_to_filename(orig_span); if let FileName::Real(RealFileName::LocalPath(path)) = filename { diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 0398d4a9961..9b1a339572e 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -248,21 +248,10 @@ impl EarlyLintPass for LintPassImpl { if last.ident.name == sym::LintPass { let expn_data = lint_pass.path.span.ctxt().outer_expn_data(); let call_site = expn_data.call_site; - if !matches!( - expn_data.kind, - ExpnKind::Macro { - kind: MacroKind::Bang, - name: sym::impl_lint_pass, - proc_macro: _ - } - ) && !matches!( - call_site.ctxt().outer_expn_data().kind, - ExpnKind::Macro { - kind: MacroKind::Bang, - name: sym::declare_lint_pass, - proc_macro: _ - } - ) { + if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass) + && call_site.ctxt().outer_expn_data().kind + != ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass) + { cx.struct_span_lint( LINT_PASS_IMPL_WITHOUT_MACRO, lint_pass.path.span, diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index 99a88f6bf61..a32caf1bc43 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -256,10 +256,6 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, } let macro_symbol = - if let hygiene::ExpnKind::Macro { kind: _, name: symbol, proc_macro: _ } = expn.kind { - symbol - } else { - Symbol::intern("panic") - }; + if let hygiene::ExpnKind::Macro(_, symbol) = expn.kind { symbol } else { sym::panic }; (expn.call_site, panic_macro, macro_symbol.as_str()) } diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs index c9b6cee5deb..63872ca9017 100644 --- a/compiler/rustc_middle/src/lint.rs +++ b/compiler/rustc_middle/src/lint.rs @@ -387,7 +387,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool { false } ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external" - ExpnKind::Macro { kind: MacroKind::Bang, name: _, proc_macro: _ } => { + ExpnKind::Macro(MacroKind::Bang, _) => { // Dummy span for the `def_site` means it's an external macro. expn_data.def_site.is_dummy() || sess.source_map().is_imported(expn_data.def_site) } diff --git a/compiler/rustc_mir/src/transform/coverage/spans.rs b/compiler/rustc_mir/src/transform/coverage/spans.rs index f62171b3c53..08cc87ccc34 100644 --- a/compiler/rustc_mir/src/transform/coverage/spans.rs +++ b/compiler/rustc_mir/src/transform/coverage/spans.rs @@ -184,11 +184,8 @@ impl CoverageSpan { self.current_macro_or_none .borrow_mut() .get_or_insert_with(|| { - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: current_macro, - proc_macro: _, - } = self.expn_span.ctxt().outer_expn_data().kind + if let ExpnKind::Macro(MacroKind::Bang, current_macro) = + self.expn_span.ctxt().outer_expn_data().kind { return Some(current_macro); } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 559a9967086..bcdae1cb43d 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1775,11 +1775,9 @@ impl<'a> Resolver<'a> { let expn_data = expn_id.expn_data(); match expn_data.kind { ExpnKind::Root - | ExpnKind::Macro { - kind: MacroKind::Bang | MacroKind::Derive, - name: _, - proc_macro: _, - } => Scope::DeriveHelpersCompat, + | ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => { + Scope::DeriveHelpersCompat + } _ => Scope::DeriveHelpers(expn_data.parent), } } diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 1727586071d..e024ade7b3c 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -319,11 +319,7 @@ impl<'a> ResolverExpand for Resolver<'a> { let expn_data = expn_id.expn_data(); match expn_data.kind { ExpnKind::Root - | ExpnKind::Macro { - name: _, - kind: MacroKind::Bang | MacroKind::Derive, - proc_macro: _, - } => { + | ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => { break; } _ => expn_id = expn_data.parent, diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index ef2bae5e287..0a8a88132e3 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -788,7 +788,7 @@ impl<'tcx> SaveContext<'tcx> { let callee = span.source_callee()?; let mac_name = match callee.kind { - ExpnKind::Macro { kind, name, proc_macro: _ } => match kind { + ExpnKind::Macro(kind, name) => match kind { MacroKind::Bang => name, // Ignore attribute macros, their spans are usually mangled diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index b2da51f8f38..fe25ba4f9ca 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -144,10 +144,7 @@ impl ExpnId { let expn_data = self.expn_data(); // Stop going up the backtrace once include! is encountered if expn_data.is_root() - || matches!( - expn_data.kind, - ExpnKind::Macro { kind: MacroKind::Bang, name: sym::include, proc_macro: _ } - ) + || expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include) { break; } @@ -850,13 +847,7 @@ pub enum ExpnKind { /// No expansion, aka root expansion. Only `ExpnId::root()` has this kind. Root, /// Expansion produced by a macro. - Macro { - kind: MacroKind, - name: Symbol, - /// If `true`, this macro is a procedural macro. This - /// flag is only used for diagnostic purposes - proc_macro: bool, - }, + Macro(MacroKind, Symbol), /// Transform done by the compiler on the AST. AstPass(AstPass), /// Desugaring done by the compiler during HIR lowering. @@ -869,7 +860,7 @@ impl ExpnKind { pub fn descr(&self) -> String { match *self { ExpnKind::Root => kw::PathRoot.to_string(), - ExpnKind::Macro { kind, name, proc_macro: _ } => match kind { + ExpnKind::Macro(macro_kind, name) => match macro_kind { MacroKind::Bang => format!("{}!", name), MacroKind::Attr => format!("#[{}]", name), MacroKind::Derive => format!("#[derive({})]", name), diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 6265470e625..84bef4b113c 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -520,10 +520,7 @@ impl Span { /// Returns `true` if `span` originates in a derive-macro's expansion. pub fn in_derive_expansion(self) -> bool { - matches!( - self.ctxt().outer_expn_data().kind, - ExpnKind::Macro { kind: MacroKind::Derive, name: _, proc_macro: _ } - ) + matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _)) } #[inline] diff --git a/src/test/ui/hygiene/unpretty-debug.stdout b/src/test/ui/hygiene/unpretty-debug.stdout index ae2857d505e..84ca046212d 100644 --- a/src/test/ui/hygiene/unpretty-debug.stdout +++ b/src/test/ui/hygiene/unpretty-debug.stdout @@ -20,7 +20,7 @@ fn y /* 0#0 */() { } /* Expansions: 0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root -1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "foo", proc_macro: false } +1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "foo") SyntaxContexts: #0: parent: #0, outer_mark: (ExpnId(0), Opaque) diff --git a/src/test/ui/proc-macro/meta-macro-hygiene.stdout b/src/test/ui/proc-macro/meta-macro-hygiene.stdout index 368326e0216..dc63d014451 100644 --- a/src/test/ui/proc-macro/meta-macro-hygiene.stdout +++ b/src/test/ui/proc-macro/meta-macro-hygiene.stdout @@ -45,10 +45,10 @@ fn main /* 0#0 */() { ; } Expansions: 0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root 1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) -2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "produce_it", proc_macro: false } +2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it") 3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) -4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "meta_macro::print_def_site", proc_macro: true } -5: parent: ExpnId(4), call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "$crate::dummy", proc_macro: true } +4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site") +5: parent: ExpnId(4), call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy") SyntaxContexts: #0: parent: #0, outer_mark: (ExpnId(0), Opaque) diff --git a/src/test/ui/proc-macro/nonterminal-token-hygiene.stdout b/src/test/ui/proc-macro/nonterminal-token-hygiene.stdout index 2911707fdb0..75e6a49b314 100644 --- a/src/test/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/src/test/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -69,10 +69,10 @@ fn main /* 0#0 */() { } Expansions: 0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root 1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) -2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "outer", proc_macro: false } +2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer") 3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports) -4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro { kind: Bang, name: "inner", proc_macro: false } -5: parent: ExpnId(4), call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "print_bang", proc_macro: true } +4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro(Bang, "inner") +5: parent: ExpnId(4), call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro(Bang, "print_bang") SyntaxContexts: #0: parent: #0, outer_mark: (ExpnId(0), Opaque) diff --git a/src/test/ui/proc-macro/span-from-proc-macro.stderr b/src/test/ui/proc-macro/span-from-proc-macro.stderr index 2cbe91afacd..9152ee60a7e 100644 --- a/src/test/ui/proc-macro/span-from-proc-macro.stderr +++ b/src/test/ui/proc-macro/span-from-proc-macro.stderr @@ -2,7 +2,7 @@ error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { - | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` + | ----------------------------------------------------------------------------------- in this expansion of `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope @@ -16,7 +16,7 @@ error[E0412]: cannot find type `OtherMissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:46:21 | LL | pub fn error_from_derive(_input: TokenStream) -> TokenStream { - | ------------------------------------------------------------ in this expansion of procedural macro `#[derive(ErrorFromDerive)]` + | ------------------------------------------------------------ in this expansion of `#[derive(ErrorFromDerive)]` ... LL | Variant(OtherMissingType) | ^^^^^^^^^^^^^^^^ not found in this scope @@ -30,7 +30,7 @@ error[E0425]: cannot find value `my_ident` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:29:9 | LL | pub fn other_error_from_bang(_input: TokenStream) -> TokenStream { - | ---------------------------------------------------------------- in this expansion of procedural macro `other_error_from_bang!` + | ---------------------------------------------------------------- in this expansion of `other_error_from_bang!` LL | custom_quote::custom_quote! { LL | my_ident | ^^^^^^^^ not found in this scope @@ -49,7 +49,7 @@ LL | let bang_error: bool = 25; | expected due to this ... LL | pub fn error_from_bang(_input: TokenStream) -> TokenStream { - | ---------------------------------------------------------- in this expansion of procedural macro `error_from_bang!` + | ---------------------------------------------------------- in this expansion of `error_from_bang!` | ::: $DIR/span-from-proc-macro.rs:15:5 | diff --git a/src/tools/clippy/clippy_lints/src/misc.rs b/src/tools/clippy/clippy_lints/src/misc.rs index 804c04fe1b8..7cfce2e61cc 100644 --- a/src/tools/clippy/clippy_lints/src/misc.rs +++ b/src/tools/clippy/clippy_lints/src/misc.rs @@ -662,14 +662,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool { use rustc_span::hygiene::MacroKind; if expr.span.from_expansion() { let data = expr.span.ctxt().outer_expn_data(); - matches!( - data.kind, - ExpnKind::Macro { - kind: MacroKind::Attr, - name: _, - proc_macro: _ - } - ) + matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _)) } else { false } diff --git a/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs b/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs index 04542146516..85257f3113c 100644 --- a/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs +++ b/src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs @@ -8,12 +8,7 @@ use super::UNIT_CMP; pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if expr.span.from_expansion() { if let Some(callee) = expr.span.source_callee() { - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: symbol, - proc_macro: _, - } = callee.kind - { + if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind { if let ExprKind::Binary(ref cmp, left, _) = expr.kind { let op = cmp.node; if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 217a1f4dded..2f10472180f 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -953,12 +953,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: mac_name, - proc_macro: _, - } = data.kind - { + if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { if mac_name.as_str() == name { return Some(new_span); } @@ -986,12 +981,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> { let data = span.ctxt().outer_expn_data(); let new_span = data.call_site; - if let ExpnKind::Macro { - kind: MacroKind::Bang, - name: mac_name, - proc_macro: _, - } = data.kind - { + if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind { if mac_name.as_str() == name { return Some(new_span); } |
