11use crate :: { AmbiguityError , AmbiguityKind , AmbiguityErrorMisc , Determinacy } ;
2- use crate :: { CrateLint , Resolver , ResolutionError , ScopeSet , Weak } ;
2+ use crate :: { CrateLint , Resolver , ResolutionError , Scope , ScopeSet , ParentScope , Weak } ;
33use crate :: { Module , ModuleKind , NameBinding , NameBindingKind , PathResult , Segment , ToNameBinding } ;
44use crate :: { is_known_tool, resolve_error} ;
55use crate :: ModuleOrUniformRoot ;
@@ -79,15 +79,6 @@ pub enum LegacyScope<'a> {
7979 Invocation ( & ' a InvocationData < ' a > ) ,
8080}
8181
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-
9182// Macro namespace is separated into two sub-namespaces, one for bang macros and
9283// one for attribute-like macros (attributes, derives).
9384// We ignore resolutions from one sub-namespace when searching names in scope for another.
@@ -474,21 +465,6 @@ impl<'a> Resolver<'a> {
474465 // but introduced by legacy plugins using `register_attribute`. Priority is somewhere
475466 // in prelude, not sure where exactly (creates ambiguities with any other prelude names).
476467
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-
492468 bitflags:: bitflags! {
493469 struct Flags : u8 {
494470 const MACRO_RULES = 1 << 0 ;
@@ -530,15 +506,15 @@ impl<'a> Resolver<'a> {
530506 ScopeSet :: Module => ( TypeNS , None , false , false ) ,
531507 } ;
532508 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 ,
536512 } ;
537513 let mut use_prelude = !parent_scope. module . no_implicit_prelude ;
538514 let mut determinacy = Determinacy :: Determined ;
539515 loop {
540516 let result = match where_to_resolve {
541- WhereToResolve :: DeriveHelpers => {
517+ Scope :: DeriveHelpers => {
542518 let mut result = Err ( Determinacy :: Determined ) ;
543519 for derive in & parent_scope. derives {
544520 let parent_scope = ParentScope { derives : Vec :: new ( ) , ..* parent_scope } ;
@@ -558,14 +534,14 @@ impl<'a> Resolver<'a> {
558534 }
559535 result
560536 }
561- WhereToResolve :: MacroRules ( legacy_scope) => match legacy_scope {
537+ Scope :: MacroRules ( legacy_scope) => match legacy_scope {
562538 LegacyScope :: Binding ( legacy_binding) if ident == legacy_binding. ident =>
563539 Ok ( ( legacy_binding. binding , Flags :: MACRO_RULES ) ) ,
564540 LegacyScope :: Invocation ( invoc) if invoc. output_legacy_scope . get ( ) . is_none ( ) =>
565541 Err ( Determinacy :: Undetermined ) ,
566542 _ => Err ( Determinacy :: Determined ) ,
567543 }
568- WhereToResolve :: CrateRoot => {
544+ Scope :: CrateRoot => {
569545 let root_ident = Ident :: new ( kw:: PathRoot , orig_ident. span ) ;
570546 let root_module = self . resolve_crate_root ( root_ident) ;
571547 let binding = self . resolve_ident_in_module_ext (
@@ -585,7 +561,7 @@ impl<'a> Resolver<'a> {
585561 Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
586562 }
587563 }
588- WhereToResolve :: Module ( module) => {
564+ Scope :: Module ( module) => {
589565 let orig_current_module = mem:: replace ( & mut self . current_module , module) ;
590566 let binding = self . resolve_ident_in_module_unadjusted_ext (
591567 ModuleOrUniformRoot :: Module ( module) ,
@@ -615,7 +591,7 @@ impl<'a> Resolver<'a> {
615591 Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
616592 }
617593 }
618- WhereToResolve :: MacroUsePrelude => {
594+ Scope :: MacroUsePrelude => {
619595 if use_prelude || rust_2015 {
620596 match self . macro_use_prelude . get ( & ident. name ) . cloned ( ) {
621597 Some ( binding) =>
@@ -628,13 +604,13 @@ impl<'a> Resolver<'a> {
628604 Err ( Determinacy :: Determined )
629605 }
630606 }
631- WhereToResolve :: BuiltinMacros => {
607+ Scope :: BuiltinMacros => {
632608 match self . builtin_macros . get ( & ident. name ) . cloned ( ) {
633609 Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
634610 None => Err ( Determinacy :: Determined ) ,
635611 }
636612 }
637- WhereToResolve :: BuiltinAttrs => {
613+ Scope :: BuiltinAttrs => {
638614 if is_builtin_attr_name ( ident. name ) {
639615 let binding = ( Res :: NonMacroAttr ( NonMacroAttrKind :: Builtin ) ,
640616 ty:: Visibility :: Public , DUMMY_SP , Mark :: root ( ) )
@@ -644,7 +620,7 @@ impl<'a> Resolver<'a> {
644620 Err ( Determinacy :: Determined )
645621 }
646622 }
647- WhereToResolve :: LegacyPluginHelpers => {
623+ Scope :: LegacyPluginHelpers => {
648624 if ( use_prelude || rust_2015) &&
649625 self . session . plugin_attributes . borrow ( ) . iter ( )
650626 . any ( |( name, _) | ident. name == * name) {
@@ -656,7 +632,7 @@ impl<'a> Resolver<'a> {
656632 Err ( Determinacy :: Determined )
657633 }
658634 }
659- WhereToResolve :: ExternPrelude => {
635+ Scope :: ExternPrelude => {
660636 if use_prelude || is_absolute_path {
661637 match self . extern_prelude_get ( ident, !record_used) {
662638 Some ( binding) => Ok ( ( binding, Flags :: PRELUDE ) ) ,
@@ -668,7 +644,7 @@ impl<'a> Resolver<'a> {
668644 Err ( Determinacy :: Determined )
669645 }
670646 }
671- WhereToResolve :: ToolPrelude => {
647+ Scope :: ToolPrelude => {
672648 if use_prelude && is_known_tool ( ident. name ) {
673649 let binding = ( Res :: ToolMod , ty:: Visibility :: Public ,
674650 DUMMY_SP , Mark :: root ( ) ) . to_name_binding ( self . arenas ) ;
@@ -677,7 +653,7 @@ impl<'a> Resolver<'a> {
677653 Err ( Determinacy :: Determined )
678654 }
679655 }
680- WhereToResolve :: StdLibPrelude => {
656+ Scope :: StdLibPrelude => {
681657 let mut result = Err ( Determinacy :: Determined ) ;
682658 if use_prelude {
683659 if let Some ( prelude) = self . prelude {
@@ -694,7 +670,7 @@ impl<'a> Resolver<'a> {
694670 }
695671 result
696672 }
697- WhereToResolve :: BuiltinTypes => {
673+ Scope :: BuiltinTypes => {
698674 match self . primitive_type_table . primitive_types . get ( & ident. name ) . cloned ( ) {
699675 Some ( prim_ty) => {
700676 let binding = ( Res :: PrimTy ( prim_ty) , ty:: Visibility :: Public ,
@@ -780,51 +756,51 @@ impl<'a> Resolver<'a> {
780756 }
781757
782758 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 (
787763 binding. parent_legacy_scope
788764 ) ,
789- LegacyScope :: Invocation ( invoc) => WhereToResolve :: MacroRules (
765+ LegacyScope :: Invocation ( invoc) => Scope :: MacroRules (
790766 invoc. output_legacy_scope . get ( ) . unwrap_or ( invoc. parent_legacy_scope )
791767 ) ,
792- LegacyScope :: Empty => WhereToResolve :: Module ( parent_scope. module ) ,
768+ LegacyScope :: Empty => Scope :: Module ( parent_scope. module ) ,
793769 }
794- WhereToResolve :: CrateRoot => match ns {
770+ Scope :: CrateRoot => match ns {
795771 TypeNS => {
796772 ident. span . adjust ( Mark :: root ( ) ) ;
797- WhereToResolve :: ExternPrelude
773+ Scope :: ExternPrelude
798774 }
799775 ValueNS | MacroNS => break ,
800776 }
801- WhereToResolve :: Module ( module) => {
777+ Scope :: Module ( module) => {
802778 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) ,
804780 None => {
805781 ident. span . adjust ( Mark :: root ( ) ) ;
806782 use_prelude = !module. no_implicit_prelude ;
807783 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 ,
811787 }
812788 }
813789 }
814790 }
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 ,
824800 ValueNS => break , // nowhere else to search
825- MacroNS => WhereToResolve :: BuiltinMacros ,
801+ MacroNS => Scope :: BuiltinMacros ,
826802 }
827- WhereToResolve :: BuiltinTypes => break , // nowhere else to search
803+ Scope :: BuiltinTypes => break , // nowhere else to search
828804 } ;
829805
830806 continue ;
0 commit comments