Skip to content

Commit 8698ba3

Browse files
committed
refactor(rustc_expand): Take &SyntaxExtension instead of only &*Kind
1 parent e014f69 commit 8698ba3

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

490490
let fragment_kind = invoc.fragment_kind;
491-
match self.expand_invoc(invoc, &ext.kind) {
491+
match self.expand_invoc(invoc, &ext) {
492492
ExpandResult::Ready(fragment) => {
493493
let mut derive_invocations = Vec::new();
494494
let derive_placeholders = self
@@ -650,7 +650,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
650650
fn expand_invoc(
651651
&mut self,
652652
invoc: Invocation,
653-
ext: &SyntaxExtensionKind,
653+
ext: &Lrc<SyntaxExtension>,
654654
) -> ExpandResult<AstFragment, Invocation> {
655655
let recursion_limit = match self.cx.reduced_recursion_limit {
656656
Some((limit, _)) => limit,
@@ -671,7 +671,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
671671

672672
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
673673
ExpandResult::Ready(match invoc.kind {
674-
InvocationKind::Bang { mac, span } => match ext {
674+
InvocationKind::Bang { mac, span } => match &ext.kind {
675675
SyntaxExtensionKind::Bang(expander) => {
676676
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
677677
Ok(tok_result) => {
@@ -701,7 +701,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
701701
}
702702
_ => unreachable!(),
703703
},
704-
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
704+
InvocationKind::Attr { attr, pos, mut item, derives } => match &ext.kind {
705705
SyntaxExtensionKind::Attr(expander) => {
706706
self.gate_proc_macro_input(&item);
707707
self.gate_proc_macro_attr_item(span, &item);
@@ -780,10 +780,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
780780
}
781781
_ => unreachable!(),
782782
},
783-
InvocationKind::Derive { path, item, is_const } => match ext {
783+
InvocationKind::Derive { path, item, is_const } => match &ext.kind {
784784
SyntaxExtensionKind::Derive(expander)
785785
| SyntaxExtensionKind::LegacyDerive(expander) => {
786-
if let SyntaxExtensionKind::Derive(..) = ext {
786+
if let SyntaxExtensionKind::Derive(..) = ext.kind {
787787
self.gate_proc_macro_input(&item);
788788
}
789789
// The `MetaItem` representing the trait to derive can't
@@ -810,18 +810,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
810810
},
811811
InvocationKind::GlobDelegation { item } => {
812812
let AssocItemKind::DelegationMac(deleg) = &item.kind else { unreachable!() };
813-
let suffixes = match ext {
814-
SyntaxExtensionKind::GlobDelegation(expander) => match expander.expand(self.cx)
815-
{
816-
ExpandResult::Ready(suffixes) => suffixes,
817-
ExpandResult::Retry(()) => {
818-
// Reassemble the original invocation for retrying.
819-
return ExpandResult::Retry(Invocation {
820-
kind: InvocationKind::GlobDelegation { item },
821-
..invoc
822-
});
813+
let suffixes = match &ext.kind {
814+
SyntaxExtensionKind::GlobDelegation(expander) => {
815+
match expander.expand(self.cx) {
816+
ExpandResult::Ready(suffixes) => suffixes,
817+
ExpandResult::Retry(()) => {
818+
// Reassemble the original invocation for retrying.
819+
return ExpandResult::Retry(Invocation {
820+
kind: InvocationKind::GlobDelegation { item },
821+
..invoc
822+
});
823+
}
823824
}
824-
},
825+
}
825826
SyntaxExtensionKind::LegacyBang(..) => {
826827
let msg = "expanded a dummy glob delegation";
827828
let guar = self.cx.dcx().span_delayed_bug(span, msg);

0 commit comments

Comments
 (0)