@@ -554,35 +554,35 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
554
554
// (open, not controlled).
555
555
// 3. Standard library prelude (de-facto closed, controlled).
556
556
// (Macro NS)
557
- // 1-2. `macro_rules` (open, not controlled), loop through legacy scopes. Have higher
557
+ // 1-3. Derive helpers (open, not controlled). All ambiguities with other names
558
+ // are currently reported as errors. They should be higher in priority than preludes
559
+ // and probably even names in modules according to the "general principles" above. They
560
+ // also should be subject to restricted shadowing because are effectively produced by
561
+ // derives (you need to resolve the derive first to add helpers into scope), but they
562
+ // should be available before the derive is expanded for compatibility.
563
+ // It's mess in general, so we are being conservative for now.
564
+ // 1-3. `macro_rules` (open, not controlled), loop through legacy scopes. Have higher
558
565
// priority than prelude macros, but create ambiguities with macros in modules.
559
- // 1-2 . Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
566
+ // 1-3 . Names in modules (both normal `mod`ules and blocks), loop through hygienic parents
560
567
// (open, not controlled). Have higher priority than prelude macros, but create
561
568
// ambiguities with `macro_rules`.
562
- // 3 . `macro_use` prelude (open, the open part is from macro expansions, not controlled).
563
- // 3a . User-defined prelude from macro-use
569
+ // 4 . `macro_use` prelude (open, the open part is from macro expansions, not controlled).
570
+ // 4a . User-defined prelude from macro-use
564
571
// (open, the open part is from macro expansions, not controlled).
565
- // 3b . Standard library prelude is currently implemented as `macro-use` (closed, controlled)
572
+ // 4b . Standard library prelude is currently implemented as `macro-use` (closed, controlled)
566
573
// 5. Language prelude: builtin macros (closed, controlled, except for legacy plugins).
567
574
// 6. Language prelude: builtin attributes (closed, controlled).
568
- // 3 -6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
575
+ // 4 -6. Legacy plugin helpers (open, not controlled). Similar to derive helpers,
569
576
// but introduced by legacy plugins using `register_attribute`. Priority is somewhere
570
577
// in prelude, not sure where exactly (creates ambiguities with any other prelude names).
571
- // N (unordered). Derive helpers (open, not controlled). All ambiguities with other names
572
- // are currently reported as errors. They should be higher in priority than preludes
573
- // and maybe even names in modules according to the "general principles" above. They
574
- // also should be subject to restricted shadowing because are effectively produced by
575
- // derives (you need to resolve the derive first to add helpers into scope), but they
576
- // should be available before the derive is expanded for compatibility.
577
- // It's mess in general, so we are being conservative for now.
578
578
579
579
enum WhereToResolve < ' a > {
580
+ DeriveHelpers ,
580
581
MacroRules ( LegacyScope < ' a > ) ,
581
582
Module ( Module < ' a > ) ,
582
583
MacroUsePrelude ,
583
584
BuiltinMacros ,
584
585
BuiltinAttrs ,
585
- DeriveHelpers ,
586
586
LegacyPluginHelpers ,
587
587
ExternPrelude ,
588
588
ToolPrelude ,
@@ -616,10 +616,30 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
616
616
let mut innermost_result: Option < ( & NameBinding , Flags , /* conflicts with */ Flags ) > = None ;
617
617
618
618
// Go through all the scopes and try to resolve the name.
619
- let mut where_to_resolve = WhereToResolve :: MacroRules ( parent_scope . legacy ) ;
619
+ let mut where_to_resolve = WhereToResolve :: DeriveHelpers ;
620
620
let mut use_prelude = !parent_scope. module . no_implicit_prelude ;
621
621
loop {
622
622
let result = match where_to_resolve {
623
+ WhereToResolve :: DeriveHelpers => {
624
+ let mut result = Err ( Determinacy :: Determined ) ;
625
+ for derive in & parent_scope. derives {
626
+ let parent_scope = ParentScope { derives : Vec :: new ( ) , ..* parent_scope } ;
627
+ if let Ok ( ( _, ext) ) = self . resolve_macro_to_def ( derive, MacroKind :: Derive ,
628
+ & parent_scope, force) {
629
+ if let SyntaxExtension :: ProcMacroDerive ( _, helper_attrs, _) = & * ext {
630
+ if helper_attrs. contains ( & ident. name ) {
631
+ let binding =
632
+ ( Def :: NonMacroAttr ( NonMacroAttrKind :: DeriveHelper ) ,
633
+ ty:: Visibility :: Public , derive. span , Mark :: root ( ) )
634
+ . to_name_binding ( self . arenas ) ;
635
+ result = Ok ( ( binding, Flags :: DERIVE_HELPERS , Flags :: all ( ) ) ) ;
636
+ break ;
637
+ }
638
+ }
639
+ }
640
+ }
641
+ result
642
+ }
623
643
WhereToResolve :: MacroRules ( legacy_scope) => match legacy_scope {
624
644
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
625
645
Ok ( ( legacy_binding. binding , Flags :: MACRO_RULES , Flags :: MODULE ) ) ,
@@ -660,26 +680,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
660
680
Err ( Determinacy :: Determined )
661
681
}
662
682
}
663
- WhereToResolve :: DeriveHelpers => {
664
- let mut result = Err ( Determinacy :: Determined ) ;
665
- for derive in & parent_scope. derives {
666
- let parent_scope = ParentScope { derives : Vec :: new ( ) , ..* parent_scope } ;
667
- if let Ok ( ( _, ext) ) = self . resolve_macro_to_def ( derive, MacroKind :: Derive ,
668
- & parent_scope, force) {
669
- if let SyntaxExtension :: ProcMacroDerive ( _, helper_attrs, _) = & * ext {
670
- if helper_attrs. contains ( & ident. name ) {
671
- let binding =
672
- ( Def :: NonMacroAttr ( NonMacroAttrKind :: DeriveHelper ) ,
673
- ty:: Visibility :: Public , derive. span , Mark :: root ( ) )
674
- . to_name_binding ( self . arenas ) ;
675
- result = Ok ( ( binding, Flags :: DERIVE_HELPERS , Flags :: all ( ) ) ) ;
676
- break ;
677
- }
678
- }
679
- }
680
- }
681
- result
682
- }
683
683
WhereToResolve :: LegacyPluginHelpers => {
684
684
if self . session . plugin_attributes . borrow ( ) . iter ( )
685
685
. any ( |( name, _) | ident. name == & * * name) {
@@ -747,6 +747,8 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
747
747
748
748
macro_rules! continue_search { ( ) => {
749
749
where_to_resolve = match where_to_resolve {
750
+ WhereToResolve :: DeriveHelpers =>
751
+ WhereToResolve :: MacroRules ( parent_scope. legacy) ,
750
752
WhereToResolve :: MacroRules ( legacy_scope) => match legacy_scope {
751
753
LegacyScope :: Binding ( binding) =>
752
754
WhereToResolve :: MacroRules ( binding. parent_legacy_scope) ,
@@ -770,8 +772,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
770
772
}
771
773
WhereToResolve :: MacroUsePrelude => WhereToResolve :: BuiltinMacros ,
772
774
WhereToResolve :: BuiltinMacros => WhereToResolve :: BuiltinAttrs ,
773
- WhereToResolve :: BuiltinAttrs => WhereToResolve :: DeriveHelpers ,
774
- WhereToResolve :: DeriveHelpers => WhereToResolve :: LegacyPluginHelpers ,
775
+ WhereToResolve :: BuiltinAttrs => WhereToResolve :: LegacyPluginHelpers ,
775
776
WhereToResolve :: LegacyPluginHelpers => break , // nowhere else to search
776
777
WhereToResolve :: ExternPrelude => WhereToResolve :: ToolPrelude ,
777
778
WhereToResolve :: ToolPrelude => WhereToResolve :: StdLibPrelude ,
0 commit comments