Skip to content

Commit eca839e

Browse files
committed
refactor(rustc_expand): Take &SyntaxExtension instead of only &*Kind
1 parent e857ce9 commit eca839e

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
@@ -491,7 +491,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
491491
self.cx.force_mode = force;
492492

493493
let fragment_kind = invoc.fragment_kind;
494-
match self.expand_invoc(invoc, &ext.kind) {
494+
match self.expand_invoc(invoc, &ext) {
495495
ExpandResult::Ready(fragment) => {
496496
let mut derive_invocations = Vec::new();
497497
let derive_placeholders = self
@@ -653,7 +653,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
653653
fn expand_invoc(
654654
&mut self,
655655
invoc: Invocation,
656-
ext: &SyntaxExtensionKind,
656+
ext: &Lrc<SyntaxExtension>,
657657
) -> ExpandResult<AstFragment, Invocation> {
658658
let recursion_limit = match self.cx.reduced_recursion_limit {
659659
Some((limit, _)) => limit,
@@ -674,7 +674,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
674674

675675
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
676676
ExpandResult::Ready(match invoc.kind {
677-
InvocationKind::Bang { mac, span } => match ext {
677+
InvocationKind::Bang { mac, span } => match &ext.kind {
678678
SyntaxExtensionKind::Bang(expander) => {
679679
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
680680
Ok(tok_result) => {
@@ -704,7 +704,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
704704
}
705705
_ => unreachable!(),
706706
},
707-
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
707+
InvocationKind::Attr { attr, pos, mut item, derives } => match &ext.kind {
708708
SyntaxExtensionKind::Attr(expander) => {
709709
self.gate_proc_macro_input(&item);
710710
self.gate_proc_macro_attr_item(span, &item);
@@ -783,10 +783,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
783783
}
784784
_ => unreachable!(),
785785
},
786-
InvocationKind::Derive { path, item, is_const } => match ext {
786+
InvocationKind::Derive { path, item, is_const } => match &ext.kind {
787787
SyntaxExtensionKind::Derive(expander)
788788
| SyntaxExtensionKind::LegacyDerive(expander) => {
789-
if let SyntaxExtensionKind::Derive(..) = ext {
789+
if let SyntaxExtensionKind::Derive(..) = ext.kind {
790790
self.gate_proc_macro_input(&item);
791791
}
792792
// The `MetaItem` representing the trait to derive can't
@@ -813,18 +813,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
813813
},
814814
InvocationKind::GlobDelegation { item } => {
815815
let AssocItemKind::DelegationMac(deleg) = &item.kind else { unreachable!() };
816-
let suffixes = match ext {
817-
SyntaxExtensionKind::GlobDelegation(expander) => match expander.expand(self.cx)
818-
{
819-
ExpandResult::Ready(suffixes) => suffixes,
820-
ExpandResult::Retry(()) => {
821-
// Reassemble the original invocation for retrying.
822-
return ExpandResult::Retry(Invocation {
823-
kind: InvocationKind::GlobDelegation { item },
824-
..invoc
825-
});
816+
let suffixes = match &ext.kind {
817+
SyntaxExtensionKind::GlobDelegation(expander) => {
818+
match expander.expand(self.cx) {
819+
ExpandResult::Ready(suffixes) => suffixes,
820+
ExpandResult::Retry(()) => {
821+
// Reassemble the original invocation for retrying.
822+
return ExpandResult::Retry(Invocation {
823+
kind: InvocationKind::GlobDelegation { item },
824+
..invoc
825+
});
826+
}
826827
}
827-
},
828+
}
828829
SyntaxExtensionKind::LegacyBang(..) => {
829830
let msg = "expanded a dummy glob delegation";
830831
let guar = self.cx.dcx().span_delayed_bug(span, msg);

0 commit comments

Comments
 (0)