@@ -357,6 +357,10 @@ where
357357 }
358358}
359359
360+ pub trait GlobDelegationExpander {
361+ fn expand ( & self , ecx : & mut ExtCtxt < ' _ > ) -> ExpandResult < Vec < ( Ident , Option < Ident > ) > , ( ) > ;
362+ }
363+
360364// Use a macro because forwarding to a simple function has type system issues
361365macro_rules! make_stmts_default {
362366 ( $me: expr) => {
@@ -714,6 +718,9 @@ pub enum SyntaxExtensionKind {
714718 /// The produced AST fragment is appended to the input AST fragment.
715719 Box < dyn MultiItemModifier + sync:: DynSync + sync:: DynSend > ,
716720 ) ,
721+
722+ /// A glob delegation.
723+ GlobDelegation ( Box < dyn GlobDelegationExpander + sync:: DynSync + sync:: DynSend > ) ,
717724}
718725
719726/// A struct representing a macro definition in "lowered" form ready for expansion.
@@ -748,7 +755,9 @@ impl SyntaxExtension {
748755 /// Returns which kind of macro calls this syntax extension.
749756 pub fn macro_kind ( & self ) -> MacroKind {
750757 match self . kind {
751- SyntaxExtensionKind :: Bang ( ..) | SyntaxExtensionKind :: LegacyBang ( ..) => MacroKind :: Bang ,
758+ SyntaxExtensionKind :: Bang ( ..)
759+ | SyntaxExtensionKind :: LegacyBang ( ..)
760+ | SyntaxExtensionKind :: GlobDelegation ( ..) => MacroKind :: Bang ,
752761 SyntaxExtensionKind :: Attr ( ..)
753762 | SyntaxExtensionKind :: LegacyAttr ( ..)
754763 | SyntaxExtensionKind :: NonMacroAttr => MacroKind :: Attr ,
@@ -922,6 +931,32 @@ impl SyntaxExtension {
922931 SyntaxExtension :: default ( SyntaxExtensionKind :: NonMacroAttr , edition)
923932 }
924933
934+ pub fn glob_delegation (
935+ trait_def_id : DefId ,
936+ impl_def_id : LocalDefId ,
937+ edition : Edition ,
938+ ) -> SyntaxExtension {
939+ struct GlobDelegationExpanderImpl {
940+ trait_def_id : DefId ,
941+ impl_def_id : LocalDefId ,
942+ }
943+ impl GlobDelegationExpander for GlobDelegationExpanderImpl {
944+ fn expand (
945+ & self ,
946+ ecx : & mut ExtCtxt < ' _ > ,
947+ ) -> ExpandResult < Vec < ( Ident , Option < Ident > ) > , ( ) > {
948+ match ecx. resolver . glob_delegation_suffixes ( self . trait_def_id , self . impl_def_id ) {
949+ Ok ( suffixes) => ExpandResult :: Ready ( suffixes) ,
950+ Err ( Indeterminate ) if ecx. force_mode => ExpandResult :: Ready ( Vec :: new ( ) ) ,
951+ Err ( Indeterminate ) => ExpandResult :: Retry ( ( ) ) ,
952+ }
953+ }
954+ }
955+
956+ let expander = GlobDelegationExpanderImpl { trait_def_id, impl_def_id } ;
957+ SyntaxExtension :: default ( SyntaxExtensionKind :: GlobDelegation ( Box :: new ( expander) ) , edition)
958+ }
959+
925960 pub fn expn_data (
926961 & self ,
927962 parent : LocalExpnId ,
@@ -1030,6 +1065,16 @@ pub trait ResolverExpand {
10301065
10311066 /// Tools registered with `#![register_tool]` and used by tool attributes and lints.
10321067 fn registered_tools ( & self ) -> & RegisteredTools ;
1068+
1069+ /// Mark this invocation id as a glob delegation.
1070+ fn register_glob_delegation ( & mut self , invoc_id : LocalExpnId ) ;
1071+
1072+ /// Names of specific methods to which glob delegation expands.
1073+ fn glob_delegation_suffixes (
1074+ & mut self ,
1075+ trait_def_id : DefId ,
1076+ impl_def_id : LocalDefId ,
1077+ ) -> Result < Vec < ( Ident , Option < Ident > ) > , Indeterminate > ;
10331078}
10341079
10351080pub trait LintStoreExpand {
0 commit comments