@@ -357,6 +357,10 @@ where
357
357
}
358
358
}
359
359
360
+ pub trait GlobDelegationExpander {
361
+ fn expand ( & self , ecx : & mut ExtCtxt < ' _ > ) -> ExpandResult < Vec < ( Ident , Option < Ident > ) > , ( ) > ;
362
+ }
363
+
360
364
// Use a macro because forwarding to a simple function has type system issues
361
365
macro_rules! make_stmts_default {
362
366
( $me: expr) => {
@@ -714,6 +718,9 @@ pub enum SyntaxExtensionKind {
714
718
/// The produced AST fragment is appended to the input AST fragment.
715
719
Box < dyn MultiItemModifier + sync:: DynSync + sync:: DynSend > ,
716
720
) ,
721
+
722
+ /// A glob delegation.
723
+ GlobDelegation ( Box < dyn GlobDelegationExpander + sync:: DynSync + sync:: DynSend > ) ,
717
724
}
718
725
719
726
/// A struct representing a macro definition in "lowered" form ready for expansion.
@@ -748,7 +755,9 @@ impl SyntaxExtension {
748
755
/// Returns which kind of macro calls this syntax extension.
749
756
pub fn macro_kind ( & self ) -> MacroKind {
750
757
match self . kind {
751
- SyntaxExtensionKind :: Bang ( ..) | SyntaxExtensionKind :: LegacyBang ( ..) => MacroKind :: Bang ,
758
+ SyntaxExtensionKind :: Bang ( ..)
759
+ | SyntaxExtensionKind :: LegacyBang ( ..)
760
+ | SyntaxExtensionKind :: GlobDelegation ( ..) => MacroKind :: Bang ,
752
761
SyntaxExtensionKind :: Attr ( ..)
753
762
| SyntaxExtensionKind :: LegacyAttr ( ..)
754
763
| SyntaxExtensionKind :: NonMacroAttr => MacroKind :: Attr ,
@@ -922,6 +931,32 @@ impl SyntaxExtension {
922
931
SyntaxExtension :: default ( SyntaxExtensionKind :: NonMacroAttr , edition)
923
932
}
924
933
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
+
925
960
pub fn expn_data (
926
961
& self ,
927
962
parent : LocalExpnId ,
@@ -1030,6 +1065,16 @@ pub trait ResolverExpand {
1030
1065
1031
1066
/// Tools registered with `#![register_tool]` and used by tool attributes and lints.
1032
1067
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 > ;
1033
1078
}
1034
1079
1035
1080
pub trait LintStoreExpand {
0 commit comments