Skip to content

Commit b6925fb

Browse files
committed
delegation: Implement glob delegation
1 parent 7dda3b8 commit b6925fb

25 files changed

+970
-25
lines changed

compiler/rustc_ast/src/ast.rs

+8
Original file line numberDiff line numberDiff line change
@@ -3110,6 +3110,7 @@ pub struct Fn {
31103110
#[derive(Clone, Encodable, Decodable, Debug)]
31113111
pub enum DelegationKind {
31123112
Single,
3113+
Glob,
31133114
List(ThinVec<Ident>),
31143115
}
31153116

@@ -3121,6 +3122,13 @@ pub struct Delegation {
31213122
pub path: Path,
31223123
pub kind: DelegationKind,
31233124
pub body: Option<P<Block>>,
3125+
pub from_glob: bool,
3126+
}
3127+
3128+
impl Delegation {
3129+
pub fn is_glob(&self) -> bool {
3130+
matches!(self.kind, DelegationKind::Glob)
3131+
}
31243132
}
31253133

31263134
#[derive(Clone, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/mut_visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1149,12 +1149,12 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
11491149
}
11501150
ItemKind::MacCall(m) => vis.visit_mac_call(m),
11511151
ItemKind::MacroDef(def) => vis.visit_macro_def(def),
1152-
ItemKind::Delegation(box Delegation { id, qself, path, kind, body }) => {
1152+
ItemKind::Delegation(box Delegation { id, qself, path, kind, body, from_glob: _ }) => {
11531153
vis.visit_id(id);
11541154
vis.visit_qself(qself);
11551155
vis.visit_path(path);
11561156
match kind {
1157-
DelegationKind::Single => {}
1157+
DelegationKind::Single | DelegationKind::Glob => {}
11581158
DelegationKind::List(suffixes) => {
11591159
for ident in suffixes {
11601160
vis.visit_ident(ident);
@@ -1203,12 +1203,12 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
12031203
visit_opt(ty, |ty| visitor.visit_ty(ty));
12041204
}
12051205
AssocItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
1206-
AssocItemKind::Delegation(box Delegation { id, qself, path, kind, body }) => {
1206+
AssocItemKind::Delegation(box Delegation { id, qself, path, kind, body, from_glob: _ }) => {
12071207
visitor.visit_id(id);
12081208
visitor.visit_qself(qself);
12091209
visitor.visit_path(path);
12101210
match kind {
1211-
DelegationKind::Single => {}
1211+
DelegationKind::Single | DelegationKind::Glob => {}
12121212
DelegationKind::List(suffixes) => {
12131213
for ident in suffixes {
12141214
visitor.visit_ident(ident);

compiler/rustc_ast/src/visit.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) -> V::Resu
382382
}
383383
ItemKind::MacCall(mac) => try_visit!(visitor.visit_mac_call(mac)),
384384
ItemKind::MacroDef(ts) => try_visit!(visitor.visit_mac_def(ts, item.id)),
385-
ItemKind::Delegation(box Delegation { id, qself, path, kind, body }) => {
385+
ItemKind::Delegation(box Delegation { id, qself, path, kind, body, from_glob: _ }) => {
386386
if let Some(qself) = qself {
387387
try_visit!(visitor.visit_ty(&qself.ty));
388388
}
389389
try_visit!(visitor.visit_path(path, *id));
390390
match kind {
391-
DelegationKind::Single => {}
391+
DelegationKind::Single | DelegationKind::Glob => {}
392392
DelegationKind::List(suffixes) => {
393393
for ident in suffixes {
394394
visitor.visit_ident(*ident);
@@ -790,13 +790,13 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(
790790
AssocItemKind::MacCall(mac) => {
791791
try_visit!(visitor.visit_mac_call(mac));
792792
}
793-
AssocItemKind::Delegation(box Delegation { id, qself, path, kind, body }) => {
793+
AssocItemKind::Delegation(box Delegation { id, qself, path, kind, body, from_glob: _ }) => {
794794
if let Some(qself) = qself {
795795
try_visit!(visitor.visit_ty(&qself.ty));
796796
}
797797
try_visit!(visitor.visit_path(path, *id));
798798
match kind {
799-
DelegationKind::Single => {}
799+
DelegationKind::Single | DelegationKind::Glob => {}
800800
DelegationKind::List(suffixes) => {
801801
for ident in suffixes {
802802
visitor.visit_ident(*ident);

compiler/rustc_expand/src/base.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@ pub enum SyntaxExtensionKind {
728728
/// The produced AST fragment is appended to the input AST fragment.
729729
Box<dyn MultiItemModifier + sync::DynSync + sync::DynSend>,
730730
),
731+
GlobDelegation(Box<dyn GlobDelegationExpander + sync::DynSync + sync::DynSend>),
732+
}
733+
734+
pub trait GlobDelegationExpander {
735+
fn expand(&self, ecx: &mut ExtCtxt<'_>) -> ExpandResult<Vec<Ident>, ()>;
731736
}
732737

733738
/// A struct representing a macro definition in "lowered" form ready for expansion.
@@ -762,7 +767,9 @@ impl SyntaxExtension {
762767
/// Returns which kind of macro calls this syntax extension.
763768
pub fn macro_kind(&self) -> MacroKind {
764769
match self.kind {
765-
SyntaxExtensionKind::Bang(..) | SyntaxExtensionKind::LegacyBang(..) => MacroKind::Bang,
770+
SyntaxExtensionKind::Bang(..)
771+
| SyntaxExtensionKind::LegacyBang(..)
772+
| SyntaxExtensionKind::GlobDelegation(..) => MacroKind::Bang,
766773
SyntaxExtensionKind::Attr(..)
767774
| SyntaxExtensionKind::LegacyAttr(..)
768775
| SyntaxExtensionKind::NonMacroAttr => MacroKind::Attr,
@@ -1044,6 +1051,13 @@ pub trait ResolverExpand {
10441051

10451052
/// Tools registered with `#![register_tool]` and used by tool attributes and lints.
10461053
fn registered_tools(&self) -> &RegisteredTools;
1054+
1055+
fn glob_delegation_suffixes(
1056+
&mut self,
1057+
def_id: DefId,
1058+
parent_def_id: LocalDefId,
1059+
) -> Result<Vec<Ident>, Indeterminate>;
1060+
fn register_glob_delegation(&mut self, invoc_id: LocalExpnId);
10471061
}
10481062

10491063
pub trait LintStoreExpand {

0 commit comments

Comments
 (0)