Skip to content

Commit e0fe67e

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

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

514514
let fragment_kind = invoc.fragment_kind;
515-
match self.expand_invoc(invoc, &ext.kind) {
515+
match self.expand_invoc(invoc, &ext) {
516516
ExpandResult::Ready(fragment) => {
517517
let mut derive_invocations = Vec::new();
518518
let derive_placeholders = self
@@ -674,7 +674,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
674674
fn expand_invoc(
675675
&mut self,
676676
invoc: Invocation,
677-
ext: &SyntaxExtensionKind,
677+
ext: &Lrc<SyntaxExtension>,
678678
) -> ExpandResult<AstFragment, Invocation> {
679679
let recursion_limit = match self.cx.reduced_recursion_limit {
680680
Some((limit, _)) => limit,
@@ -695,7 +695,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
695695

696696
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
697697
ExpandResult::Ready(match invoc.kind {
698-
InvocationKind::Bang { mac, span } => match ext {
698+
InvocationKind::Bang { mac, span } => match &ext.kind {
699699
SyntaxExtensionKind::Bang(expander) => {
700700
match expander.expand(self.cx, span, mac.args.tokens.clone()) {
701701
Ok(tok_result) => {
@@ -725,7 +725,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
725725
}
726726
_ => unreachable!(),
727727
},
728-
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
728+
InvocationKind::Attr { attr, pos, mut item, derives } => match &ext.kind {
729729
SyntaxExtensionKind::Attr(expander) => {
730730
self.gate_proc_macro_input(&item);
731731
self.gate_proc_macro_attr_item(span, &item);
@@ -804,10 +804,10 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
804804
}
805805
_ => unreachable!(),
806806
},
807-
InvocationKind::Derive { path, item, is_const } => match ext {
807+
InvocationKind::Derive { path, item, is_const } => match &ext.kind {
808808
SyntaxExtensionKind::Derive(expander)
809809
| SyntaxExtensionKind::LegacyDerive(expander) => {
810-
if let SyntaxExtensionKind::Derive(..) = ext {
810+
if let SyntaxExtensionKind::Derive(..) = ext.kind {
811811
self.gate_proc_macro_input(&item);
812812
}
813813
// The `MetaItem` representing the trait to derive can't
@@ -834,18 +834,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
834834
},
835835
InvocationKind::GlobDelegation { item, of_trait } => {
836836
let AssocItemKind::DelegationMac(deleg) = &item.kind else { unreachable!() };
837-
let suffixes = match ext {
838-
SyntaxExtensionKind::GlobDelegation(expander) => match expander.expand(self.cx)
839-
{
840-
ExpandResult::Ready(suffixes) => suffixes,
841-
ExpandResult::Retry(()) => {
842-
// Reassemble the original invocation for retrying.
843-
return ExpandResult::Retry(Invocation {
844-
kind: InvocationKind::GlobDelegation { item, of_trait },
845-
..invoc
846-
});
837+
let suffixes = match &ext.kind {
838+
SyntaxExtensionKind::GlobDelegation(expander) => {
839+
match expander.expand(self.cx) {
840+
ExpandResult::Ready(suffixes) => suffixes,
841+
ExpandResult::Retry(()) => {
842+
// Reassemble the original invocation for retrying.
843+
return ExpandResult::Retry(Invocation {
844+
kind: InvocationKind::GlobDelegation { item, of_trait },
845+
..invoc
846+
});
847+
}
847848
}
848-
},
849+
}
849850
SyntaxExtensionKind::LegacyBang(..) => {
850851
let msg = "expanded a dummy glob delegation";
851852
let guar = self.cx.dcx().span_delayed_bug(span, msg);

0 commit comments

Comments
 (0)