1
1
use crate :: { AmbiguityError , AmbiguityKind , AmbiguityErrorMisc , Determinacy } ;
2
- use crate :: { CrateLint , Resolver , ResolutionError , ScopeSet , Weak } ;
2
+ use crate :: { CrateLint , Resolver , ResolutionError , Scope , ScopeSet , ParentScope , Weak } ;
3
3
use crate :: { Module , ModuleKind , NameBinding , NameBindingKind , PathResult , Segment , ToNameBinding } ;
4
4
use crate :: { is_known_tool, resolve_error} ;
5
5
use crate :: ModuleOrUniformRoot ;
@@ -79,15 +79,6 @@ pub enum LegacyScope<'a> {
79
79
Invocation ( & ' a InvocationData < ' a > ) ,
80
80
}
81
81
82
- /// Everything you need to resolve a macro or import path.
83
- #[ derive( Clone , Debug ) ]
84
- pub struct ParentScope < ' a > {
85
- crate module : Module < ' a > ,
86
- crate expansion : Mark ,
87
- crate legacy : LegacyScope < ' a > ,
88
- crate derives : Vec < ast:: Path > ,
89
- }
90
-
91
82
// Macro namespace is separated into two sub-namespaces, one for bang macros and
92
83
// one for attribute-like macros (attributes, derives).
93
84
// We ignore resolutions from one sub-namespace when searching names in scope for another.
@@ -474,21 +465,6 @@ impl<'a> Resolver<'a> {
474
465
// but introduced by legacy plugins using `register_attribute`. Priority is somewhere
475
466
// in prelude, not sure where exactly (creates ambiguities with any other prelude names).
476
467
477
- enum WhereToResolve < ' a > {
478
- DeriveHelpers ,
479
- MacroRules ( LegacyScope < ' a > ) ,
480
- CrateRoot ,
481
- Module ( Module < ' a > ) ,
482
- MacroUsePrelude ,
483
- BuiltinMacros ,
484
- BuiltinAttrs ,
485
- LegacyPluginHelpers ,
486
- ExternPrelude ,
487
- ToolPrelude ,
488
- StdLibPrelude ,
489
- BuiltinTypes ,
490
- }
491
-
492
468
bitflags:: bitflags! {
493
469
struct Flags : u8 {
494
470
const MACRO_RULES = 1 << 0 ;
@@ -530,15 +506,15 @@ impl<'a> Resolver<'a> {
530
506
ScopeSet :: Module => ( TypeNS , None , false , false ) ,
531
507
} ;
532
508
let mut where_to_resolve = match ns {
533
- _ if is_absolute_path => WhereToResolve :: CrateRoot ,
534
- TypeNS | ValueNS => WhereToResolve :: Module ( parent_scope. module ) ,
535
- MacroNS => WhereToResolve :: DeriveHelpers ,
509
+ _ if is_absolute_path => Scope :: CrateRoot ,
510
+ TypeNS | ValueNS => Scope :: Module ( parent_scope. module ) ,
511
+ MacroNS => Scope :: DeriveHelpers ,
536
512
} ;
537
513
let mut use_prelude = !parent_scope. module . no_implicit_prelude ;
538
514
let mut determinacy = Determinacy :: Determined ;
539
515
loop {
540
516
let result = match where_to_resolve {
541
- WhereToResolve :: DeriveHelpers => {
517
+ Scope :: DeriveHelpers => {
542
518
let mut result = Err ( Determinacy :: Determined ) ;
543
519
for derive in & parent_scope. derives {
544
520
let parent_scope = ParentScope { derives : Vec :: new ( ) , ..* parent_scope } ;
@@ -558,14 +534,14 @@ impl<'a> Resolver<'a> {
558
534
}
559
535
result
560
536
}
561
- WhereToResolve :: MacroRules ( legacy_scope) => match legacy_scope {
537
+ Scope :: MacroRules ( legacy_scope) => match legacy_scope {
562
538
LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
563
539
Ok ( ( legacy_binding. binding , Flags :: MACRO_RULES ) ) ,
564
540
LegacyScope :: Invocation ( invoc) if invoc. output_legacy_scope . get ( ) . is_none ( ) =>
565
541
Err ( Determinacy :: Undetermined ) ,
566
542
_ => Err ( Determinacy :: Determined ) ,
567
543
}
568
- WhereToResolve :: CrateRoot => {
544
+ Scope :: CrateRoot => {
569
545
let root_ident = Ident :: new ( kw:: PathRoot , orig_ident. span ) ;
570
546
let root_module = self . resolve_crate_root ( root_ident) ;
571
547
let binding = self . resolve_ident_in_module_ext (
@@ -585,7 +561,7 @@ impl<'a> Resolver<'a> {
585
561
Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
586
562
}
587
563
}
588
- WhereToResolve :: Module ( module) => {
564
+ Scope :: Module ( module) => {
589
565
let orig_current_module = mem:: replace ( & mut self . current_module , module) ;
590
566
let binding = self . resolve_ident_in_module_unadjusted_ext (
591
567
ModuleOrUniformRoot :: Module ( module) ,
@@ -615,7 +591,7 @@ impl<'a> Resolver<'a> {
615
591
Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
616
592
}
617
593
}
618
- WhereToResolve :: MacroUsePrelude => {
594
+ Scope :: MacroUsePrelude => {
619
595
if use_prelude || rust_2015 {
620
596
match self . macro_use_prelude . get ( & ident. name ) . cloned ( ) {
621
597
Some ( binding) =>
@@ -628,13 +604,13 @@ impl<'a> Resolver<'a> {
628
604
Err ( Determinacy :: Determined )
629
605
}
630
606
}
631
- WhereToResolve :: BuiltinMacros => {
607
+ Scope :: BuiltinMacros => {
632
608
match self . builtin_macros . get ( & ident. name ) . cloned ( ) {
633
609
Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
634
610
None => Err ( Determinacy :: Determined ) ,
635
611
}
636
612
}
637
- WhereToResolve :: BuiltinAttrs => {
613
+ Scope :: BuiltinAttrs => {
638
614
if is_builtin_attr_name ( ident. name ) {
639
615
let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ,
640
616
ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
@@ -644,7 +620,7 @@ impl<'a> Resolver<'a> {
644
620
Err ( Determinacy :: Determined )
645
621
}
646
622
}
647
- WhereToResolve :: LegacyPluginHelpers => {
623
+ Scope :: LegacyPluginHelpers => {
648
624
if ( use_prelude || rust_2015) &&
649
625
self . session . plugin_attributes . borrow ( ) . iter ( )
650
626
. any ( |( name, _) | ident. name == * name) {
@@ -656,7 +632,7 @@ impl<'a> Resolver<'a> {
656
632
Err ( Determinacy :: Determined )
657
633
}
658
634
}
659
- WhereToResolve :: ExternPrelude => {
635
+ Scope :: ExternPrelude => {
660
636
if use_prelude || is_absolute_path {
661
637
match self . extern_prelude_get ( ident, !record_used) {
662
638
Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
@@ -668,7 +644,7 @@ impl<'a> Resolver<'a> {
668
644
Err ( Determinacy :: Determined )
669
645
}
670
646
}
671
- WhereToResolve :: ToolPrelude => {
647
+ Scope :: ToolPrelude => {
672
648
if use_prelude && is_known_tool ( ident. name ) {
673
649
let binding = ( Res :: ToolMod , ty:: Visibility :: Public ,
674
650
DUMMY_SP , Mark :: root ( ) ) . to_name_binding ( self . arenas ) ;
@@ -677,7 +653,7 @@ impl<'a> Resolver<'a> {
677
653
Err ( Determinacy :: Determined )
678
654
}
679
655
}
680
- WhereToResolve :: StdLibPrelude => {
656
+ Scope :: StdLibPrelude => {
681
657
let mut result = Err ( Determinacy :: Determined ) ;
682
658
if use_prelude {
683
659
if let Some ( prelude) = self . prelude {
@@ -694,7 +670,7 @@ impl<'a> Resolver<'a> {
694
670
}
695
671
result
696
672
}
697
- WhereToResolve :: BuiltinTypes => {
673
+ Scope :: BuiltinTypes => {
698
674
match self . primitive_type_table . primitive_types . get ( & ident. name ) . cloned ( ) {
699
675
Some ( prim_ty) => {
700
676
let binding = ( Res :: PrimTy ( prim_ty) , ty:: Visibility :: Public ,
@@ -780,51 +756,51 @@ impl<'a> Resolver<'a> {
780
756
}
781
757
782
758
where_to_resolve = match where_to_resolve {
783
- WhereToResolve :: DeriveHelpers =>
784
- WhereToResolve :: MacroRules ( parent_scope. legacy ) ,
785
- WhereToResolve :: MacroRules ( legacy_scope) => match legacy_scope {
786
- LegacyScope :: Binding ( binding) => WhereToResolve :: MacroRules (
759
+ Scope :: DeriveHelpers =>
760
+ Scope :: MacroRules ( parent_scope. legacy ) ,
761
+ Scope :: MacroRules ( legacy_scope) => match legacy_scope {
762
+ LegacyScope :: Binding ( binding) => Scope :: MacroRules (
787
763
binding. parent_legacy_scope
788
764
) ,
789
- LegacyScope :: Invocation ( invoc) => WhereToResolve :: MacroRules (
765
+ LegacyScope :: Invocation ( invoc) => Scope :: MacroRules (
790
766
invoc. output_legacy_scope . get ( ) . unwrap_or ( invoc. parent_legacy_scope )
791
767
) ,
792
- LegacyScope :: Empty => WhereToResolve :: Module ( parent_scope. module ) ,
768
+ LegacyScope :: Empty => Scope :: Module ( parent_scope. module ) ,
793
769
}
794
- WhereToResolve :: CrateRoot => match ns {
770
+ Scope :: CrateRoot => match ns {
795
771
TypeNS => {
796
772
ident. span . adjust ( Mark :: root ( ) ) ;
797
- WhereToResolve :: ExternPrelude
773
+ Scope :: ExternPrelude
798
774
}
799
775
ValueNS | MacroNS => break ,
800
776
}
801
- WhereToResolve :: Module ( module) => {
777
+ Scope :: Module ( module) => {
802
778
match self . hygienic_lexical_parent ( module, & mut ident. span ) {
803
- Some ( parent_module) => WhereToResolve :: Module ( parent_module) ,
779
+ Some ( parent_module) => Scope :: Module ( parent_module) ,
804
780
None => {
805
781
ident. span . adjust ( Mark :: root ( ) ) ;
806
782
use_prelude = !module. no_implicit_prelude ;
807
783
match ns {
808
- TypeNS => WhereToResolve :: ExternPrelude ,
809
- ValueNS => WhereToResolve :: StdLibPrelude ,
810
- MacroNS => WhereToResolve :: MacroUsePrelude ,
784
+ TypeNS => Scope :: ExternPrelude ,
785
+ ValueNS => Scope :: StdLibPrelude ,
786
+ MacroNS => Scope :: MacroUsePrelude ,
811
787
}
812
788
}
813
789
}
814
790
}
815
- WhereToResolve :: MacroUsePrelude => WhereToResolve :: StdLibPrelude ,
816
- WhereToResolve :: BuiltinMacros => WhereToResolve :: BuiltinAttrs ,
817
- WhereToResolve :: BuiltinAttrs => WhereToResolve :: LegacyPluginHelpers ,
818
- WhereToResolve :: LegacyPluginHelpers => break , // nowhere else to search
819
- WhereToResolve :: ExternPrelude if is_absolute_path => break ,
820
- WhereToResolve :: ExternPrelude => WhereToResolve :: ToolPrelude ,
821
- WhereToResolve :: ToolPrelude => WhereToResolve :: StdLibPrelude ,
822
- WhereToResolve :: StdLibPrelude => match ns {
823
- TypeNS => WhereToResolve :: BuiltinTypes ,
791
+ Scope :: MacroUsePrelude => Scope :: StdLibPrelude ,
792
+ Scope :: BuiltinMacros => Scope :: BuiltinAttrs ,
793
+ Scope :: BuiltinAttrs => Scope :: LegacyPluginHelpers ,
794
+ Scope :: LegacyPluginHelpers => break , // nowhere else to search
795
+ Scope :: ExternPrelude if is_absolute_path => break ,
796
+ Scope :: ExternPrelude => Scope :: ToolPrelude ,
797
+ Scope :: ToolPrelude => Scope :: StdLibPrelude ,
798
+ Scope :: StdLibPrelude => match ns {
799
+ TypeNS => Scope :: BuiltinTypes ,
824
800
ValueNS => break , // nowhere else to search
825
- MacroNS => WhereToResolve :: BuiltinMacros ,
801
+ MacroNS => Scope :: BuiltinMacros ,
826
802
}
827
- WhereToResolve :: BuiltinTypes => break , // nowhere else to search
803
+ Scope :: BuiltinTypes => break , // nowhere else to search
828
804
} ;
829
805
830
806
continue ;
0 commit comments