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