Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 28f4dba

Browse files
committed
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`.
1 parent a31431f commit 28f4dba

File tree

19 files changed

+37
-118
lines changed

19 files changed

+37
-118
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,7 @@ pub trait Emitter {
309309
// are some which do actually involve macros.
310310
ExpnKind::Inlined | ExpnKind::Desugaring(..) | ExpnKind::AstPass(..) => None,
311311

312-
ExpnKind::Macro { kind: macro_kind, name, proc_macro: _ } => {
313-
Some((macro_kind, name))
314-
}
312+
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
315313
}
316314
});
317315

@@ -372,19 +370,10 @@ pub trait Emitter {
372370
new_labels
373371
.push((trace.call_site, "in the inlined copy of this code".to_string()));
374372
} else if always_backtrace {
375-
let proc_macro = if let ExpnKind::Macro { kind: _, name: _, proc_macro: true } =
376-
trace.kind
377-
{
378-
"procedural macro "
379-
} else {
380-
""
381-
};
382-
383373
new_labels.push((
384374
trace.def_site,
385375
format!(
386-
"in this expansion of {}`{}`{}",
387-
proc_macro,
376+
"in this expansion of `{}`{}",
388377
trace.kind.descr(),
389378
if macro_backtrace.len() > 1 {
390379
// if macro_backtrace.len() == 1 it'll be
@@ -410,11 +399,7 @@ pub trait Emitter {
410399
// and it needs an "in this macro invocation" label to match that.
411400
let redundant_span = trace.call_site.contains(sp);
412401

413-
if !redundant_span
414-
&& matches!(
415-
trace.kind,
416-
ExpnKind::Macro { kind: MacroKind::Bang, name: _, proc_macro: _ }
417-
)
402+
if !redundant_span && matches!(trace.kind, ExpnKind::Macro(MacroKind::Bang, _))
418403
|| always_backtrace
419404
{
420405
new_labels.push((

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,8 @@ impl SyntaxExtension {
811811
macro_def_id: Option<DefId>,
812812
parent_module: Option<DefId>,
813813
) -> ExpnData {
814-
use SyntaxExtensionKind::*;
815-
let proc_macro = match self.kind {
816-
// User-defined proc macro
817-
Bang(..) | Attr(..) | Derive(..) => true,
818-
// Consider everthing else to be not a proc
819-
// macro for diagnostic purposes
820-
LegacyBang(..) | LegacyAttr(..) | NonMacroAttr { .. } | LegacyDerive(..) => false,
821-
};
822814
ExpnData::new(
823-
ExpnKind::Macro { kind: self.macro_kind(), name: descr, proc_macro },
815+
ExpnKind::Macro(self.macro_kind(), descr),
824816
parent,
825817
call_site,
826818
self.span,

compiler/rustc_expand/src/proc_macro_server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ fn ident_name_compatibility_hack(
812812
rustc: &mut Rustc<'_>,
813813
) -> Option<(rustc_span::symbol::Ident, bool)> {
814814
if let NtIdent(ident, is_raw) = nt {
815-
if let ExpnKind::Macro { name: macro_name, .. } = orig_span.ctxt().outer_expn_data().kind {
815+
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
816816
let source_map = rustc.sess.source_map();
817817
let filename = source_map.span_to_filename(orig_span);
818818
if let FileName::Real(RealFileName::LocalPath(path)) = filename {

compiler/rustc_lint/src/internal.rs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,10 @@ impl EarlyLintPass for LintPassImpl {
248248
if last.ident.name == sym::LintPass {
249249
let expn_data = lint_pass.path.span.ctxt().outer_expn_data();
250250
let call_site = expn_data.call_site;
251-
if !matches!(
252-
expn_data.kind,
253-
ExpnKind::Macro {
254-
kind: MacroKind::Bang,
255-
name: sym::impl_lint_pass,
256-
proc_macro: _
257-
}
258-
) && !matches!(
259-
call_site.ctxt().outer_expn_data().kind,
260-
ExpnKind::Macro {
261-
kind: MacroKind::Bang,
262-
name: sym::declare_lint_pass,
263-
proc_macro: _
264-
}
265-
) {
251+
if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass)
252+
&& call_site.ctxt().outer_expn_data().kind
253+
!= ExpnKind::Macro(MacroKind::Bang, sym::declare_lint_pass)
254+
{
266255
cx.struct_span_lint(
267256
LINT_PASS_IMPL_WITHOUT_MACRO,
268257
lint_pass.path.span,

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,6 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
256256
}
257257

258258
let macro_symbol =
259-
if let hygiene::ExpnKind::Macro { kind: _, name: symbol, proc_macro: _ } = expn.kind {
260-
symbol
261-
} else {
262-
Symbol::intern("panic")
263-
};
259+
if let hygiene::ExpnKind::Macro(_, symbol) = expn.kind { symbol } else { sym::panic };
264260
(expn.call_site, panic_macro, macro_symbol.as_str())
265261
}

compiler/rustc_middle/src/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
387387
false
388388
}
389389
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
390-
ExpnKind::Macro { kind: MacroKind::Bang, name: _, proc_macro: _ } => {
390+
ExpnKind::Macro(MacroKind::Bang, _) => {
391391
// Dummy span for the `def_site` means it's an external macro.
392392
expn_data.def_site.is_dummy() || sess.source_map().is_imported(expn_data.def_site)
393393
}

compiler/rustc_mir/src/transform/coverage/spans.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,8 @@ impl CoverageSpan {
184184
self.current_macro_or_none
185185
.borrow_mut()
186186
.get_or_insert_with(|| {
187-
if let ExpnKind::Macro {
188-
kind: MacroKind::Bang,
189-
name: current_macro,
190-
proc_macro: _,
191-
} = self.expn_span.ctxt().outer_expn_data().kind
187+
if let ExpnKind::Macro(MacroKind::Bang, current_macro) =
188+
self.expn_span.ctxt().outer_expn_data().kind
192189
{
193190
return Some(current_macro);
194191
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,11 +1775,9 @@ impl<'a> Resolver<'a> {
17751775
let expn_data = expn_id.expn_data();
17761776
match expn_data.kind {
17771777
ExpnKind::Root
1778-
| ExpnKind::Macro {
1779-
kind: MacroKind::Bang | MacroKind::Derive,
1780-
name: _,
1781-
proc_macro: _,
1782-
} => Scope::DeriveHelpersCompat,
1778+
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
1779+
Scope::DeriveHelpersCompat
1780+
}
17831781
_ => Scope::DeriveHelpers(expn_data.parent),
17841782
}
17851783
}

compiler/rustc_resolve/src/macros.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,7 @@ impl<'a> ResolverExpand for Resolver<'a> {
319319
let expn_data = expn_id.expn_data();
320320
match expn_data.kind {
321321
ExpnKind::Root
322-
| ExpnKind::Macro {
323-
name: _,
324-
kind: MacroKind::Bang | MacroKind::Derive,
325-
proc_macro: _,
326-
} => {
322+
| ExpnKind::Macro(MacroKind::Bang | MacroKind::Derive, _) => {
327323
break;
328324
}
329325
_ => expn_id = expn_data.parent,

compiler/rustc_save_analysis/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'tcx> SaveContext<'tcx> {
788788
let callee = span.source_callee()?;
789789

790790
let mac_name = match callee.kind {
791-
ExpnKind::Macro { kind, name, proc_macro: _ } => match kind {
791+
ExpnKind::Macro(kind, name) => match kind {
792792
MacroKind::Bang => name,
793793

794794
// Ignore attribute macros, their spans are usually mangled

0 commit comments

Comments
 (0)