Skip to content

Commit 2507253

Browse files
committed
refactor(rustc_expand): Take &SyntaxExtension instead of only &*Kind
1 parent 3db813e commit 2507253

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

compiler/rustc_expand/src/expand.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
490490
self.cx.force_mode = force;
491491

492492
let fragment_kind = invoc.fragment_kind;
493-
match self.expand_invoc(invoc, &ext.kind) {
493+
match self.expand_invoc(invoc, &ext) {
494494
ExpandResult::Ready(fragment) => {
495495
let mut derive_invocations = Vec::new();
496496
let derive_placeholders = self
@@ -652,7 +652,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
652652
fn expand_invoc(
653653
&mut self,
654654
invoc: Invocation,
655-
ext: &SyntaxExtensionKind,
655+
ext: &Lrc<SyntaxExtension>,
656656
) -> ExpandResult<AstFragment, Invocation> {
657657
let recursion_limit = match self.cx.reduced_recursion_limit {
658658
Some((limit, _)) => limit,
@@ -673,7 +673,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
673673

674674
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
675675
ExpandResult::Ready(match invoc.kind {
676-
InvocationKind::Bang { mac, span } => match ext {
676+
InvocationKind::Bang { mac, span } => match &ext.kind {
677677
SyntaxExtensionKind::Bang(expander) => {
678678
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
679679
Ok(tok_result) => {
@@ -703,7 +703,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
703703
}
704704
_ => unreachable!(),
705705
},
706-
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
706+
InvocationKind::Attr { attr, pos, mut item, derives } => match &ext.kind {
707707
SyntaxExtensionKind::Attr(expander) => {
708708
self.gate_proc_macro_input(&item);
709709
self.gate_proc_macro_attr_item(span, &item);
@@ -782,10 +782,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
782782
}
783783
_ => unreachable!(),
784784
},
785-
InvocationKind::Derive { path, item, is_const } => match ext {
785+
InvocationKind::Derive { path, item, is_const } => match &ext.kind {
786786
SyntaxExtensionKind::Derive(expander)
787787
| SyntaxExtensionKind::LegacyDerive(expander) => {
788-
if let SyntaxExtensionKind::Derive(..) = ext {
788+
if let SyntaxExtensionKind::Derive(..) = ext.kind {
789789
self.gate_proc_macro_input(&item);
790790
}
791791
// The `MetaItem` representing the trait to derive can't
@@ -812,18 +812,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
812812
},
813813
InvocationKind::GlobDelegation { item } => {
814814
let AssocItemKind::DelegationMac(deleg) = &item.kind else { unreachable!() };
815-
let suffixes = match ext {
816-
SyntaxExtensionKind::GlobDelegation(expander) => match expander.expand(self.cx)
817-
{
818-
ExpandResult::Ready(suffixes) => suffixes,
819-
ExpandResult::Retry(()) => {
820-
// Reassemble the original invocation for retrying.
821-
return ExpandResult::Retry(Invocation {
822-
kind: InvocationKind::GlobDelegation { item },
823-
..invoc
824-
});
815+
let suffixes = match &ext.kind {
816+
SyntaxExtensionKind::GlobDelegation(expander) => {
817+
match expander.expand(self.cx) {
818+
ExpandResult::Ready(suffixes) => suffixes,
819+
ExpandResult::Retry(()) => {
820+
// Reassemble the original invocation for retrying.
821+
return ExpandResult::Retry(Invocation {
822+
kind: InvocationKind::GlobDelegation { item },
823+
..invoc
824+
});
825+
}
825826
}
826-
},
827+
}
827828
SyntaxExtensionKind::LegacyBang(..) => {
828829
let msg = "expanded a dummy glob delegation";
829830
let guar = self.cx.dcx().span_delayed_bug(span, msg);

0 commit comments

Comments
 (0)