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