@@ -22,9 +22,15 @@ use crate::{
2222 AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , BindingKey , CmResolver , Determinacy ,
2323 Finalize , ImportKind , LexicalScopeBinding , Module , ModuleKind , ModuleOrUniformRoot ,
2424 NameBinding , NameBindingKind , ParentScope , PathResult , PrivacyError , Res , ResolutionError ,
25- Resolver , Scope , ScopeSet , Segment , Stage , Used , Weak , errors,
25+ Resolver , Scope , ScopeSet , Segment , Stage , Used , errors,
2626} ;
2727
28+ #[ derive( Debug ) ]
29+ enum Weak {
30+ Yes ,
31+ No ,
32+ }
33+
2834#[ derive( Copy , Clone ) ]
2935pub enum UsePrelude {
3036 No ,
@@ -815,7 +821,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
815821 ignore_import : Option < Import < ' ra > > ,
816822 ) -> Result < NameBinding < ' ra > , Determinacy > {
817823 self . resolve_ident_in_module ( module, ident, ns, parent_scope, None , None , ignore_import)
818- . map_err ( |( determinacy, _) | determinacy)
819824 }
820825
821826 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -828,7 +833,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
828833 finalize : Option < Finalize > ,
829834 ignore_binding : Option < NameBinding < ' ra > > ,
830835 ignore_import : Option < Import < ' ra > > ,
831- ) -> Result < NameBinding < ' ra > , ( Determinacy , Weak ) > {
836+ ) -> Result < NameBinding < ' ra > , Determinacy > {
832837 let tmp_parent_scope;
833838 let mut adjusted_parent_scope = parent_scope;
834839 match module {
@@ -851,72 +856,62 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
851856 ident,
852857 ns,
853858 adjusted_parent_scope,
854- Shadowing :: Unrestricted ,
855859 finalize,
856860 ignore_binding,
857861 ignore_import,
858862 )
859863 }
860864
861- /// Attempts to resolve `ident` in namespaces `ns` of `module`.
862- /// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete.
865+ /// Attempts to resolve `ident` in namespace `ns` of `module`.
863866 #[ instrument( level = "debug" , skip( self ) ) ]
864867 fn resolve_ident_in_virt_module_unadjusted < ' r > (
865868 self : CmResolver < ' r , ' ra , ' tcx > ,
866869 module : ModuleOrUniformRoot < ' ra > ,
867870 ident : Ident ,
868871 ns : Namespace ,
869872 parent_scope : & ParentScope < ' ra > ,
870- shadowing : Shadowing ,
871873 finalize : Option < Finalize > ,
872- // This binding should be ignored during in-module resolution, so that we don't get
873- // "self-confirming" import resolutions during import validation and checking.
874874 ignore_binding : Option < NameBinding < ' ra > > ,
875875 ignore_import : Option < Import < ' ra > > ,
876- ) -> Result < NameBinding < ' ra > , ( Determinacy , Weak ) > {
876+ ) -> Result < NameBinding < ' ra > , Determinacy > {
877877 match module {
878- ModuleOrUniformRoot :: Module ( module) => self . resolve_ident_in_module_unadjusted (
879- module,
878+ ModuleOrUniformRoot :: Module ( module) => self
879+ . resolve_ident_in_module_unadjusted (
880+ module,
881+ ident,
882+ ns,
883+ parent_scope,
884+ Shadowing :: Unrestricted ,
885+ finalize,
886+ ignore_binding,
887+ ignore_import,
888+ )
889+ . map_err ( |( determinacy, _) | determinacy) ,
890+ ModuleOrUniformRoot :: ModuleAndExternPrelude ( module) => self . resolve_ident_in_scope_set (
880891 ident,
881- ns ,
892+ ScopeSet :: ModuleAndExternPrelude ( ns , module ) ,
882893 parent_scope,
883- shadowing,
884894 finalize,
895+ finalize. is_some ( ) ,
885896 ignore_binding,
886897 ignore_import,
887898 ) ,
888- ModuleOrUniformRoot :: ModuleAndExternPrelude ( module) => {
889- assert_eq ! ( shadowing, Shadowing :: Unrestricted ) ;
890- let binding = self . resolve_ident_in_scope_set (
891- ident,
892- ScopeSet :: ModuleAndExternPrelude ( ns, module) ,
893- parent_scope,
894- finalize,
895- finalize. is_some ( ) ,
896- ignore_binding,
897- ignore_import,
898- ) ;
899- return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
900- }
901899 ModuleOrUniformRoot :: ExternPrelude => {
902- assert_eq ! ( shadowing, Shadowing :: Unrestricted ) ;
903- return if ns != TypeNS {
904- Err ( ( Determined , Weak :: No ) )
900+ if ns != TypeNS {
901+ Err ( Determined )
905902 } else {
906- let binding = self . resolve_ident_in_scope_set (
903+ self . resolve_ident_in_scope_set (
907904 ident,
908905 ScopeSet :: ExternPrelude ,
909906 parent_scope,
910907 finalize,
911908 finalize. is_some ( ) ,
912909 ignore_binding,
913910 ignore_import,
914- ) ;
915- return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
916- } ;
911+ )
912+ }
917913 }
918914 ModuleOrUniformRoot :: CurrentScope => {
919- assert_eq ! ( shadowing, Shadowing :: Unrestricted ) ;
920915 if ns == TypeNS {
921916 if ident. name == kw:: Crate || ident. name == kw:: DollarCrate {
922917 let module = self . resolve_crate_root ( ident) ;
@@ -928,20 +923,20 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
928923 }
929924 }
930925
931- let binding = self . resolve_ident_in_scope_set (
926+ self . resolve_ident_in_scope_set (
932927 ident,
933928 ScopeSet :: All ( ns) ,
934929 parent_scope,
935930 finalize,
936931 finalize. is_some ( ) ,
937932 ignore_binding,
938933 ignore_import,
939- ) ;
940- return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
934+ )
941935 }
942936 }
943937 }
944938
939+ /// Attempts to resolve `ident` in namespace `ns` of `module`.
945940 fn resolve_ident_in_module_unadjusted < ' r > (
946941 mut self : CmResolver < ' r , ' ra , ' tcx > ,
947942 module : Module < ' ra > ,
@@ -950,6 +945,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
950945 parent_scope : & ParentScope < ' ra > ,
951946 shadowing : Shadowing ,
952947 finalize : Option < Finalize > ,
948+ // This binding should be ignored during in-module resolution, so that we don't get
949+ // "self-confirming" import resolutions during import validation and checking.
953950 ignore_binding : Option < NameBinding < ' ra > > ,
954951 ignore_import : Option < Import < ' ra > > ,
955952 ) -> Result < NameBinding < ' ra > , ( Determinacy , Weak ) > {
@@ -1236,15 +1233,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12361233 ignore_binding,
12371234 ignore_import,
12381235 ) {
1239- Err ( ( Determined , _ ) ) => continue ,
1236+ Err ( Determined ) => continue ,
12401237 Ok ( binding)
12411238 if !self . is_accessible_from ( binding. vis , single_import. parent_scope . module ) =>
12421239 {
12431240 continue ;
12441241 }
1245- Ok ( _) | Err ( ( Undetermined , _) ) => {
1246- return true ;
1247- }
1242+ Ok ( _) | Err ( Undetermined ) => return true ,
12481243 }
12491244 }
12501245
@@ -1761,17 +1756,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17611756 }
17621757
17631758 let binding = if let Some ( module) = module {
1764- self . reborrow ( )
1765- . resolve_ident_in_module (
1766- module,
1767- ident,
1768- ns,
1769- parent_scope,
1770- finalize,
1771- ignore_binding,
1772- ignore_import,
1773- )
1774- . map_err ( |( determinacy, _) | determinacy)
1759+ self . reborrow ( ) . resolve_ident_in_module (
1760+ module,
1761+ ident,
1762+ ns,
1763+ parent_scope,
1764+ finalize,
1765+ ignore_binding,
1766+ ignore_import,
1767+ )
17751768 } else if let Some ( ribs) = ribs
17761769 && let Some ( TypeNS | ValueNS ) = opt_ns
17771770 {
0 commit comments