@@ -19,7 +19,7 @@ use crate::{
19
19
AmbiguityError , AmbiguityErrorMisc , AmbiguityKind , BindingKey , CmResolver , Determinacy ,
20
20
Finalize , ImportKind , LexicalScopeBinding , Module , ModuleKind , ModuleOrUniformRoot ,
21
21
NameBinding , NameBindingKind , ParentScope , PathResult , PrivacyError , Res , ResolutionError ,
22
- Resolver , Scope , ScopeSet , Segment , Used , Weak , errors,
22
+ Resolver , Scope , ScopeSet , Segment , Shadowing , Used , Weak , errors,
23
23
} ;
24
24
25
25
#[ derive( Copy , Clone ) ]
@@ -34,12 +34,6 @@ impl From<UsePrelude> for bool {
34
34
}
35
35
}
36
36
37
- #[ derive( Debug , PartialEq , Clone , Copy ) ]
38
- enum Shadowing {
39
- Restricted ,
40
- Unrestricted ,
41
- }
42
-
43
37
bitflags:: bitflags! {
44
38
#[ derive( Clone , Copy , Debug ) ]
45
39
struct Flags : u8 {
@@ -113,18 +107,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
113
107
let ( ns, macro_kind) = match scope_set {
114
108
ScopeSet :: All ( ns)
115
109
| ScopeSet :: ModuleAndExternPrelude ( ns, _)
116
- | ScopeSet :: Late ( ns, ..) => ( ns, None ) ,
110
+ | ScopeSet :: Module ( _, ns, _) => ( ns, None ) ,
111
+ ScopeSet :: Late ( ns, ..) => ( ns, None ) ,
117
112
ScopeSet :: Macro ( macro_kind) => ( MacroNS , Some ( macro_kind) ) ,
118
113
} ;
119
114
let module = match scope_set {
120
115
// Start with the specified module.
121
- ScopeSet :: Late ( _, module, _) | ScopeSet :: ModuleAndExternPrelude ( _, module) => module,
116
+ ScopeSet :: Late ( _, module, _)
117
+ | ScopeSet :: ModuleAndExternPrelude ( _, module)
118
+ | ScopeSet :: Module ( module, ..) => module,
122
119
// Jump out of trait or enum modules, they do not act as scopes.
123
120
_ => parent_scope. module . nearest_item_scope ( ) ,
124
121
} ;
122
+
123
+ let module_scope = matches ! ( scope_set, ScopeSet :: Module ( ..) ) ;
125
124
let module_and_extern_prelude = matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) ) ;
126
125
let mut scope = match ns {
127
- _ if module_and_extern_prelude => Scope :: NonGlobModule ( module, None ) ,
126
+ _ if ( module_and_extern_prelude || module_scope ) => Scope :: NonGlobModule ( module, None ) ,
128
127
TypeNS | ValueNS => Scope :: NonGlobModule ( module, None ) ,
129
128
MacroNS => Scope :: DeriveHelpers ( parent_scope. expansion ) ,
130
129
} ;
@@ -198,6 +197,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
198
197
}
199
198
ValueNS | MacroNS => break ,
200
199
} ,
200
+ Scope :: GlobModule ( ..) if module_scope => break ,
201
201
Scope :: NonGlobModule ( module, prev_lint_id) => {
202
202
use_prelude = !module. no_implicit_prelude ;
203
203
Scope :: GlobModule ( module, prev_lint_id)
@@ -417,7 +417,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
417
417
let ( ns, macro_kind) = match scope_set {
418
418
ScopeSet :: All ( ns)
419
419
| ScopeSet :: ModuleAndExternPrelude ( ns, _)
420
- | ScopeSet :: Late ( ns, ..) => ( ns, None ) ,
420
+ | ScopeSet :: Module ( _, ns, _) => ( ns, None ) ,
421
+ ScopeSet :: Late ( ns, ..) => ( ns, None ) ,
421
422
ScopeSet :: Macro ( macro_kind) => ( MacroNS , Some ( macro_kind) ) ,
422
423
} ;
423
424
@@ -500,7 +501,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
500
501
} ,
501
502
Scope :: NonGlobModule ( module, derive_fallback_lint_id) => {
502
503
let ( adjusted_parent_scope, finalize) =
503
- if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) ) {
504
+ if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) )
505
+ || matches ! ( scope_set, ScopeSet :: Module ( ..) )
506
+ {
504
507
( parent_scope, finalize)
505
508
} else {
506
509
(
@@ -514,10 +517,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
514
517
ident,
515
518
ns,
516
519
adjusted_parent_scope,
517
- if matches ! ( scope_set, ScopeSet :: Late ( .. ) ) {
518
- Shadowing :: Unrestricted
519
- } else {
520
- Shadowing :: Restricted
520
+ match scope_set {
521
+ ScopeSet :: Late ( .. ) => Shadowing :: Unrestricted ,
522
+ ScopeSet :: Module ( _ , _ , shadowing ) => shadowing ,
523
+ _ => Shadowing :: Restricted ,
521
524
} ,
522
525
finalize,
523
526
ignore_binding,
@@ -539,6 +542,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
539
542
) ;
540
543
}
541
544
545
+ // Don't visit Scope::GlobModule after successful resolution in
546
+ // Scope::NonGlobModule with ScopeSet::Module.
547
+ if matches ! ( scope_set, ScopeSet :: Module ( ..) ) {
548
+ return Some ( Ok ( binding) ) ;
549
+ }
550
+
542
551
let misc_flags = this. create_module_misc_flags ( module) ;
543
552
Ok ( ( binding, Flags :: NON_GLOB_MODULE | misc_flags) )
544
553
}
@@ -548,12 +557,23 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
548
557
Err ( ( Determinacy :: Undetermined , Weak :: Yes ) ) => {
549
558
Err ( Determinacy :: Undetermined )
550
559
}
551
- Err ( ( Determinacy :: Determined , _) ) => Err ( Determinacy :: Determined ) ,
560
+ Err ( ( Determinacy :: Determined , weak) ) => {
561
+ // Only go through Glob Scope with `Weak::Yes` errors in ScopeSet::Module
562
+ if matches ! ( scope_set, ScopeSet :: Module ( ..) )
563
+ && matches ! ( weak, Weak :: No )
564
+ {
565
+ return Some ( Err ( Determinacy :: Determined ) ) ;
566
+ }
567
+
568
+ Err ( Determinacy :: Determined )
569
+ }
552
570
}
553
571
}
554
572
Scope :: GlobModule ( module, derive_fallback_lint_id) => {
555
573
let ( adjusted_parent_scope, finalize) =
556
- if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) ) {
574
+ if matches ! ( scope_set, ScopeSet :: ModuleAndExternPrelude ( ..) )
575
+ || matches ! ( scope_set, ScopeSet :: Module ( ..) )
576
+ {
557
577
( parent_scope, finalize)
558
578
} else {
559
579
(
@@ -567,10 +587,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
567
587
ident,
568
588
ns,
569
589
adjusted_parent_scope,
570
- if matches ! ( scope_set, ScopeSet :: Late ( .. ) ) {
571
- Shadowing :: Unrestricted
572
- } else {
573
- Shadowing :: Restricted
590
+ match scope_set {
591
+ ScopeSet :: Late ( .. ) => Shadowing :: Unrestricted ,
592
+ ScopeSet :: Module ( _ , _ , shadowing ) => shadowing ,
593
+ _ => Shadowing :: Restricted ,
574
594
} ,
575
595
finalize. map ( |finalize| Finalize { used : Used :: Scope , ..finalize } ) ,
576
596
ignore_binding,
@@ -831,7 +851,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
831
851
ignore_import : Option < Import < ' ra > > ,
832
852
) -> Result < NameBinding < ' ra > , Determinacy > {
833
853
self . resolve_ident_in_module ( module, ident, ns, parent_scope, None , None , ignore_import)
834
- . map_err ( |( determinacy, _) | determinacy)
835
854
}
836
855
837
856
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -844,7 +863,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
844
863
finalize : Option < Finalize > ,
845
864
ignore_binding : Option < NameBinding < ' ra > > ,
846
865
ignore_import : Option < Import < ' ra > > ,
847
- ) -> Result < NameBinding < ' ra > , ( Determinacy , Weak ) > {
866
+ ) -> Result < NameBinding < ' ra > , Determinacy > {
848
867
let tmp_parent_scope;
849
868
let mut adjusted_parent_scope = parent_scope;
850
869
match module {
@@ -888,35 +907,42 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
888
907
// "self-confirming" import resolutions during import validation and checking.
889
908
ignore_binding : Option < NameBinding < ' ra > > ,
890
909
ignore_import : Option < Import < ' ra > > ,
891
- ) -> Result < NameBinding < ' ra > , ( Determinacy , Weak ) > {
892
- let module = match module {
893
- ModuleOrUniformRoot :: Module ( module) => module,
910
+ ) -> Result < NameBinding < ' ra > , Determinacy > {
911
+ match module {
912
+ ModuleOrUniformRoot :: Module ( module) => self . early_resolve_ident_in_lexical_scope (
913
+ ident,
914
+ ScopeSet :: Module ( module, ns, shadowing) ,
915
+ parent_scope,
916
+ finalize,
917
+ finalize. is_some ( ) ,
918
+ ignore_binding,
919
+ ignore_import,
920
+ ) ,
894
921
ModuleOrUniformRoot :: ModuleAndExternPrelude ( module) => {
895
922
assert_eq ! ( shadowing, Shadowing :: Unrestricted ) ;
896
- let binding = self . early_resolve_ident_in_lexical_scope (
923
+ self . early_resolve_ident_in_lexical_scope (
897
924
ident,
898
925
ScopeSet :: ModuleAndExternPrelude ( ns, module) ,
899
926
parent_scope,
900
927
finalize,
901
928
finalize. is_some ( ) ,
902
929
ignore_binding,
903
930
ignore_import,
904
- ) ;
905
- return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
931
+ )
906
932
}
907
933
ModuleOrUniformRoot :: ExternPrelude => {
908
934
assert_eq ! ( shadowing, Shadowing :: Unrestricted ) ;
909
935
return if ns != TypeNS {
910
- Err ( ( Determined , Weak :: No ) )
936
+ Err ( Determined )
911
937
} else if let Some ( binding) =
912
938
self . reborrow ( ) . extern_prelude_get ( ident, finalize. is_some ( ) )
913
939
{
914
940
Ok ( binding)
915
941
} else if !self . graph_root . unexpanded_invocations . borrow ( ) . is_empty ( ) {
916
942
// Macro-expanded `extern crate` items can add names to extern prelude.
917
- Err ( ( Undetermined , Weak :: No ) )
943
+ Err ( Undetermined )
918
944
} else {
919
- Err ( ( Determined , Weak :: No ) )
945
+ Err ( Determined )
920
946
} ;
921
947
}
922
948
ModuleOrUniformRoot :: CurrentScope => {
@@ -932,47 +958,17 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
932
958
}
933
959
}
934
960
935
- let binding = self . early_resolve_ident_in_lexical_scope (
961
+ self . early_resolve_ident_in_lexical_scope (
936
962
ident,
937
963
ScopeSet :: All ( ns) ,
938
964
parent_scope,
939
965
finalize,
940
966
finalize. is_some ( ) ,
941
967
ignore_binding,
942
968
ignore_import,
943
- ) ;
944
- return binding. map_err ( |determinacy| ( determinacy, Weak :: No ) ) ;
945
- }
946
- } ;
947
-
948
- match self . reborrow ( ) . resolve_ident_in_non_glob_module_unadjusted (
949
- module,
950
- ident,
951
- ns,
952
- parent_scope,
953
- shadowing,
954
- finalize,
955
- ignore_binding,
956
- ignore_import,
957
- ) {
958
- Ok ( binding) => return Ok ( binding) ,
959
- Err ( ( _, Weak :: No ) ) => {
960
- return Err ( ( Determined , Weak :: No ) ) ;
969
+ )
961
970
}
962
- // no non-glob binding was found, check for glob binding
963
- Err ( ( _, Weak :: Yes ) ) => { }
964
971
}
965
-
966
- self . reborrow ( ) . resolve_ident_in_glob_module_unadjusted (
967
- module,
968
- ident,
969
- ns,
970
- parent_scope,
971
- shadowing,
972
- finalize,
973
- ignore_binding,
974
- ignore_import,
975
- )
976
972
}
977
973
978
974
fn resolve_ident_in_non_glob_module_unadjusted < ' r > (
@@ -1176,13 +1172,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1176
1172
) ;
1177
1173
1178
1174
match result {
1179
- Err ( ( Determined , _ ) ) => continue ,
1175
+ Err ( Determined ) => continue ,
1180
1176
Ok ( binding)
1181
1177
if !self . is_accessible_from ( binding. vis , glob_import. parent_scope . module ) =>
1182
1178
{
1183
1179
continue ;
1184
1180
}
1185
- Ok ( _) | Err ( ( Undetermined , _ ) ) => return ( Undetermined , Weak :: Yes ) ,
1181
+ Ok ( _) | Err ( Undetermined ) => return ( Undetermined , Weak :: Yes ) ,
1186
1182
}
1187
1183
}
1188
1184
@@ -1332,13 +1328,13 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1332
1328
ignore_binding,
1333
1329
ignore_import,
1334
1330
) {
1335
- Err ( ( Determined , _ ) ) => continue ,
1331
+ Err ( Determined ) => continue ,
1336
1332
Ok ( binding)
1337
1333
if !self . is_accessible_from ( binding. vis , single_import. parent_scope . module ) =>
1338
1334
{
1339
1335
continue ;
1340
1336
}
1341
- Ok ( _) | Err ( ( Undetermined , _ ) ) => {
1337
+ Ok ( _) | Err ( Undetermined ) => {
1342
1338
return true ;
1343
1339
}
1344
1340
}
@@ -1803,17 +1799,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1803
1799
}
1804
1800
1805
1801
let binding = if let Some ( module) = module {
1806
- self . reborrow ( )
1807
- . resolve_ident_in_module (
1808
- module,
1809
- ident,
1810
- ns,
1811
- parent_scope,
1812
- finalize,
1813
- ignore_binding,
1814
- ignore_import,
1815
- )
1816
- . map_err ( |( determinacy, _) | determinacy)
1802
+ self . reborrow ( ) . resolve_ident_in_module (
1803
+ module,
1804
+ ident,
1805
+ ns,
1806
+ parent_scope,
1807
+ finalize,
1808
+ ignore_binding,
1809
+ ignore_import,
1810
+ )
1817
1811
} else if let Some ( ribs) = ribs
1818
1812
&& let Some ( TypeNS | ValueNS ) = opt_ns
1819
1813
{
0 commit comments