Skip to content

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

compiler/rustc_span/src/hygiene.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ impl ExpnId {
144144
let expn_data = self.expn_data();
145145
// Stop going up the backtrace once include! is encountered
146146
if expn_data.is_root()
147-
|| matches!(
148-
expn_data.kind,
149-
ExpnKind::Macro { kind: MacroKind::Bang, name: sym::include, proc_macro: _ }
150-
)
147+
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
151148
{
152149
break;
153150
}
@@ -850,13 +847,7 @@ pub enum ExpnKind {
850847
/// No expansion, aka root expansion. Only `ExpnId::root()` has this kind.
851848
Root,
852849
/// Expansion produced by a macro.
853-
Macro {
854-
kind: MacroKind,
855-
name: Symbol,
856-
/// If `true`, this macro is a procedural macro. This
857-
/// flag is only used for diagnostic purposes
858-
proc_macro: bool,
859-
},
850+
Macro(MacroKind, Symbol),
860851
/// Transform done by the compiler on the AST.
861852
AstPass(AstPass),
862853
/// Desugaring done by the compiler during HIR lowering.
@@ -869,7 +860,7 @@ impl ExpnKind {
869860
pub fn descr(&self) -> String {
870861
match *self {
871862
ExpnKind::Root => kw::PathRoot.to_string(),
872-
ExpnKind::Macro { kind, name, proc_macro: _ } => match kind {
863+
ExpnKind::Macro(macro_kind, name) => match macro_kind {
873864
MacroKind::Bang => format!("{}!", name),
874865
MacroKind::Attr => format!("#[{}]", name),
875866
MacroKind::Derive => format!("#[derive({})]", name),

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,7 @@ impl Span {
520520

521521
/// Returns `true` if `span` originates in a derive-macro's expansion.
522522
pub fn in_derive_expansion(self) -> bool {
523-
matches!(
524-
self.ctxt().outer_expn_data().kind,
525-
ExpnKind::Macro { kind: MacroKind::Derive, name: _, proc_macro: _ }
526-
)
523+
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
527524
}
528525

529526
#[inline]

src/test/ui/hygiene/unpretty-debug.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn y /* 0#0 */() { }
2020
/*
2121
Expansions:
2222
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
23-
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "foo", proc_macro: false }
23+
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "foo")
2424

2525
SyntaxContexts:
2626
#0: parent: #0, outer_mark: (ExpnId(0), Opaque)

src/test/ui/proc-macro/meta-macro-hygiene.stdout

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ fn main /* 0#0 */() { ; }
4545
Expansions:
4646
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
4747
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
48-
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "produce_it", proc_macro: false }
48+
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "produce_it")
4949
3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
50-
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 }
51-
5: parent: ExpnId(4), call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "$crate::dummy", proc_macro: true }
50+
4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #0, kind: Macro(Bang, "meta_macro::print_def_site")
51+
5: parent: ExpnId(4), call_site_ctxt: #5, def_site_ctxt: #0, kind: Macro(Bang, "$crate::dummy")
5252

5353
SyntaxContexts:
5454
#0: parent: #0, outer_mark: (ExpnId(0), Opaque)

src/test/ui/proc-macro/nonterminal-token-hygiene.stdout

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ fn main /* 0#0 */() { }
6969
Expansions:
7070
0: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Root
7171
1: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
72-
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "outer", proc_macro: false }
72+
2: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: Macro(Bang, "outer")
7373
3: parent: ExpnId(0), call_site_ctxt: #0, def_site_ctxt: #0, kind: AstPass(StdImports)
74-
4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro { kind: Bang, name: "inner", proc_macro: false }
75-
5: parent: ExpnId(4), call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro { kind: Bang, name: "print_bang", proc_macro: true }
74+
4: parent: ExpnId(2), call_site_ctxt: #4, def_site_ctxt: #4, kind: Macro(Bang, "inner")
75+
5: parent: ExpnId(4), call_site_ctxt: #6, def_site_ctxt: #0, kind: Macro(Bang, "print_bang")
7676

7777
SyntaxContexts:
7878
#0: parent: #0, outer_mark: (ExpnId(0), Opaque)

src/test/ui/proc-macro/span-from-proc-macro.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0412]: cannot find type `MissingType` in this scope
22
--> $DIR/auxiliary/span-from-proc-macro.rs:37:20
33
|
44
LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream {
5-
| ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]`
5+
| ----------------------------------------------------------------------------------- in this expansion of `#[error_from_attribute]`
66
...
77
LL | field: MissingType
88
| ^^^^^^^^^^^ not found in this scope
@@ -16,7 +16,7 @@ error[E0412]: cannot find type `OtherMissingType` in this scope
1616
--> $DIR/auxiliary/span-from-proc-macro.rs:46:21
1717
|
1818
LL | pub fn error_from_derive(_input: TokenStream) -> TokenStream {
19-
| ------------------------------------------------------------ in this expansion of procedural macro `#[derive(ErrorFromDerive)]`
19+
| ------------------------------------------------------------ in this expansion of `#[derive(ErrorFromDerive)]`
2020
...
2121
LL | Variant(OtherMissingType)
2222
| ^^^^^^^^^^^^^^^^ not found in this scope
@@ -30,7 +30,7 @@ error[E0425]: cannot find value `my_ident` in this scope
3030
--> $DIR/auxiliary/span-from-proc-macro.rs:29:9
3131
|
3232
LL | pub fn other_error_from_bang(_input: TokenStream) -> TokenStream {
33-
| ---------------------------------------------------------------- in this expansion of procedural macro `other_error_from_bang!`
33+
| ---------------------------------------------------------------- in this expansion of `other_error_from_bang!`
3434
LL | custom_quote::custom_quote! {
3535
LL | my_ident
3636
| ^^^^^^^^ not found in this scope
@@ -49,7 +49,7 @@ LL | let bang_error: bool = 25;
4949
| expected due to this
5050
...
5151
LL | pub fn error_from_bang(_input: TokenStream) -> TokenStream {
52-
| ---------------------------------------------------------- in this expansion of procedural macro `error_from_bang!`
52+
| ---------------------------------------------------------- in this expansion of `error_from_bang!`
5353
|
5454
::: $DIR/span-from-proc-macro.rs:15:5
5555
|

src/tools/clippy/clippy_lints/src/misc.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -662,14 +662,7 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
662662
use rustc_span::hygiene::MacroKind;
663663
if expr.span.from_expansion() {
664664
let data = expr.span.ctxt().outer_expn_data();
665-
matches!(
666-
data.kind,
667-
ExpnKind::Macro {
668-
kind: MacroKind::Attr,
669-
name: _,
670-
proc_macro: _
671-
}
672-
)
665+
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
673666
} else {
674667
false
675668
}

src/tools/clippy/clippy_lints/src/unit_types/unit_cmp.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ use super::UNIT_CMP;
88
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
99
if expr.span.from_expansion() {
1010
if let Some(callee) = expr.span.source_callee() {
11-
if let ExpnKind::Macro {
12-
kind: MacroKind::Bang,
13-
name: symbol,
14-
proc_macro: _,
15-
} = callee.kind
16-
{
11+
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
1712
if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
1813
let op = cmp.node;
1914
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -953,12 +953,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
953953
let data = span.ctxt().outer_expn_data();
954954
let new_span = data.call_site;
955955

956-
if let ExpnKind::Macro {
957-
kind: MacroKind::Bang,
958-
name: mac_name,
959-
proc_macro: _,
960-
} = data.kind
961-
{
956+
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
962957
if mac_name.as_str() == name {
963958
return Some(new_span);
964959
}
@@ -986,12 +981,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
986981
let data = span.ctxt().outer_expn_data();
987982
let new_span = data.call_site;
988983

989-
if let ExpnKind::Macro {
990-
kind: MacroKind::Bang,
991-
name: mac_name,
992-
proc_macro: _,
993-
} = data.kind
994-
{
984+
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
995985
if mac_name.as_str() == name {
996986
return Some(new_span);
997987
}

0 commit comments

Comments
 (0)