@@ -73,8 +73,6 @@ pub(crate) enum ImportKind<'ra> {
7373 target : Ident ,
7474 /// Name declarations introduced by the import.
7575 decls : PerNS < CmCell < PendingDecl < ' ra > > > ,
76- /// `true` for `...::{self [as target]}` imports, `false` otherwise.
77- type_ns_only : bool ,
7876 /// Did this import result from a nested import? i.e. `use foo::{bar, baz};`
7977 nested : bool ,
8078 /// The ID of the `UseTree` that imported this `Import`.
@@ -115,7 +113,7 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
115113 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
116114 use ImportKind :: * ;
117115 match self {
118- Single { source, target, decls, type_ns_only , nested, id, .. } => f
116+ Single { source, target, decls, nested, id, .. } => f
119117 . debug_struct ( "Single" )
120118 . field ( "source" , source)
121119 . field ( "target" , target)
@@ -124,7 +122,6 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
124122 "decls" ,
125123 & decls. clone ( ) . map ( |b| b. into_inner ( ) . decl ( ) . map ( |_| format_args ! ( ".." ) ) ) ,
126124 )
127- . field ( "type_ns_only" , type_ns_only)
128125 . field ( "nested" , nested)
129126 . field ( "id" , id)
130127 . finish ( ) ,
@@ -1004,10 +1001,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10041001 } ;
10051002
10061003 import. imported_module . set_unchecked ( Some ( module) ) ;
1007- let ( source, target, bindings, type_ns_only) = match import. kind {
1008- ImportKind :: Single { source, target, ref decls, type_ns_only, .. } => {
1009- ( source, target, decls, type_ns_only)
1010- }
1004+ let ( source, target, bindings) = match import. kind {
1005+ ImportKind :: Single { source, target, ref decls, .. } => ( source, target, decls) ,
10111006 ImportKind :: Glob { .. } => {
10121007 self . get_mut_unchecked ( ) . resolve_glob_import ( import) ;
10131008 return 0 ;
@@ -1017,64 +1012,62 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10171012
10181013 let mut indeterminate_count = 0 ;
10191014 self . per_ns_cm ( |mut this, ns| {
1020- if !type_ns_only || ns == TypeNS {
1021- if bindings[ ns] . get ( ) != PendingDecl :: Pending {
1022- return ;
1023- } ;
1024- let binding_result = this. reborrow ( ) . maybe_resolve_ident_in_module (
1025- module,
1026- source,
1027- ns,
1028- & import. parent_scope ,
1029- Some ( import) ,
1030- ) ;
1031- let parent = import. parent_scope . module ;
1032- let binding = match binding_result {
1033- Ok ( binding) => {
1034- if binding. is_assoc_item ( )
1035- && !this. tcx . features ( ) . import_trait_associated_functions ( )
1036- {
1037- feature_err (
1038- this. tcx . sess ,
1039- sym:: import_trait_associated_functions,
1040- import. span ,
1041- "`use` associated items of traits is unstable" ,
1042- )
1043- . emit ( ) ;
1044- }
1045- // We need the `target`, `source` can be extracted.
1046- let import_decl = this. new_import_decl ( binding, import) ;
1047- this. get_mut_unchecked ( ) . plant_decl_into_local_module (
1048- IdentKey :: new ( target) ,
1015+ if bindings[ ns] . get ( ) != PendingDecl :: Pending {
1016+ return ;
1017+ } ;
1018+ let binding_result = this. reborrow ( ) . maybe_resolve_ident_in_module (
1019+ module,
1020+ source,
1021+ ns,
1022+ & import. parent_scope ,
1023+ Some ( import) ,
1024+ ) ;
1025+ let parent = import. parent_scope . module ;
1026+ let binding = match binding_result {
1027+ Ok ( binding) => {
1028+ if binding. is_assoc_item ( )
1029+ && !this. tcx . features ( ) . import_trait_associated_functions ( )
1030+ {
1031+ feature_err (
1032+ this. tcx . sess ,
1033+ sym:: import_trait_associated_functions,
1034+ import. span ,
1035+ "`use` associated items of traits is unstable" ,
1036+ )
1037+ . emit ( ) ;
1038+ }
1039+ // We need the `target`, `source` can be extracted.
1040+ let import_decl = this. new_import_decl ( binding, import) ;
1041+ this. get_mut_unchecked ( ) . plant_decl_into_local_module (
1042+ IdentKey :: new ( target) ,
1043+ target. span ,
1044+ ns,
1045+ import_decl,
1046+ ) ;
1047+ PendingDecl :: Ready ( Some ( import_decl) )
1048+ }
1049+ Err ( Determinacy :: Determined ) => {
1050+ // Don't remove underscores from `single_imports`, they were never added.
1051+ if target. name != kw:: Underscore {
1052+ let key = BindingKey :: new ( IdentKey :: new ( target) , ns) ;
1053+ this. get_mut_unchecked ( ) . update_local_resolution (
1054+ parent. expect_local ( ) ,
1055+ key,
10491056 target. span ,
1050- ns,
1051- import_decl,
1057+ false ,
1058+ |_, resolution| {
1059+ resolution. single_imports . swap_remove ( & import) ;
1060+ } ,
10521061 ) ;
1053- PendingDecl :: Ready ( Some ( import_decl) )
10541062 }
1055- Err ( Determinacy :: Determined ) => {
1056- // Don't remove underscores from `single_imports`, they were never added.
1057- if target. name != kw:: Underscore {
1058- let key = BindingKey :: new ( IdentKey :: new ( target) , ns) ;
1059- this. get_mut_unchecked ( ) . update_local_resolution (
1060- parent. expect_local ( ) ,
1061- key,
1062- target. span ,
1063- false ,
1064- |_, resolution| {
1065- resolution. single_imports . swap_remove ( & import) ;
1066- } ,
1067- ) ;
1068- }
1069- PendingDecl :: Ready ( None )
1070- }
1071- Err ( Determinacy :: Undetermined ) => {
1072- indeterminate_count += 1 ;
1073- PendingDecl :: Pending
1074- }
1075- } ;
1076- bindings[ ns] . set_unchecked ( binding) ;
1077- }
1063+ PendingDecl :: Ready ( None )
1064+ }
1065+ Err ( Determinacy :: Undetermined ) => {
1066+ indeterminate_count += 1 ;
1067+ PendingDecl :: Pending
1068+ }
1069+ } ;
1070+ bindings[ ns] . set_unchecked ( binding) ;
10781071 } ) ;
10791072
10801073 indeterminate_count
@@ -1215,10 +1208,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12151208 PathResult :: Indeterminate => unreachable ! ( ) ,
12161209 } ;
12171210
1218- let ( ident, target, bindings, type_ns_only, import_id) = match import. kind {
1219- ImportKind :: Single { source, target, ref decls, type_ns_only, id, .. } => {
1220- ( source, target, decls, type_ns_only, id)
1221- }
1211+ let ( ident, target, bindings, import_id) = match import. kind {
1212+ ImportKind :: Single { source, target, ref decls, id, .. } => ( source, target, decls, id) ,
12221213 ImportKind :: Glob { ref max_vis, id } => {
12231214 if import. module_path . len ( ) <= 1 {
12241215 // HACK(eddyb) `lint_if_path_starts_with_module` needs at least
@@ -1286,86 +1277,82 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12861277
12871278 let mut all_ns_err = true ;
12881279 self . per_ns ( |this, ns| {
1289- if !type_ns_only || ns == TypeNS {
1290- let binding = this. cm ( ) . resolve_ident_in_module (
1291- module,
1292- ident,
1293- ns,
1294- & import. parent_scope ,
1295- Some ( Finalize {
1296- report_private : false ,
1297- import : Some ( import. summary ( ) ) ,
1298- ..finalize
1299- } ) ,
1300- bindings[ ns] . get ( ) . decl ( ) ,
1301- Some ( import) ,
1302- ) ;
1280+ let binding = this. cm ( ) . resolve_ident_in_module (
1281+ module,
1282+ ident,
1283+ ns,
1284+ & import. parent_scope ,
1285+ Some ( Finalize {
1286+ report_private : false ,
1287+ import : Some ( import. summary ( ) ) ,
1288+ ..finalize
1289+ } ) ,
1290+ bindings[ ns] . get ( ) . decl ( ) ,
1291+ Some ( import) ,
1292+ ) ;
13031293
1304- match binding {
1305- Ok ( binding) => {
1306- // Consistency checks, analogous to `finalize_macro_resolutions`.
1307- let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1308- let initial_binding = binding. import_source ( ) ;
1309- all_ns_err = false ;
1310- if target. name == kw:: Underscore
1311- && initial_binding. is_extern_crate ( )
1312- && !initial_binding. is_import ( )
1313- {
1314- let used = if import. module_path . is_empty ( ) {
1315- Used :: Scope
1316- } else {
1317- Used :: Other
1318- } ;
1319- this. record_use ( ident, binding, used) ;
1320- }
1321- initial_binding. res ( )
1322- } ) ;
1323- let res = binding. res ( ) ;
1324- let has_ambiguity_error =
1325- this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1326- if res == Res :: Err || has_ambiguity_error {
1327- this. dcx ( )
1328- . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1329- return ;
1330- }
1331- if let Some ( initial_res) = initial_res {
1332- if res != initial_res && !this. issue_145575_hack_applied {
1333- span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1334- }
1335- } else if this. privacy_errors . is_empty ( ) {
1336- this. dcx ( )
1337- . create_err ( CannotDetermineImportResolution { span : import. span } )
1338- . emit ( ) ;
1294+ match binding {
1295+ Ok ( binding) => {
1296+ // Consistency checks, analogous to `finalize_macro_resolutions`.
1297+ let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1298+ let initial_binding = binding. import_source ( ) ;
1299+ all_ns_err = false ;
1300+ if target. name == kw:: Underscore
1301+ && initial_binding. is_extern_crate ( )
1302+ && !initial_binding. is_import ( )
1303+ {
1304+ let used = if import. module_path . is_empty ( ) {
1305+ Used :: Scope
1306+ } else {
1307+ Used :: Other
1308+ } ;
1309+ this. record_use ( ident, binding, used) ;
13391310 }
1311+ initial_binding. res ( )
1312+ } ) ;
1313+ let res = binding. res ( ) ;
1314+ let has_ambiguity_error =
1315+ this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1316+ if res == Res :: Err || has_ambiguity_error {
1317+ this. dcx ( )
1318+ . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1319+ return ;
13401320 }
1341- Err ( ..) => {
1342- // FIXME: This assert may fire if public glob is later shadowed by a private
1343- // single import (see test `issue-55884-2.rs`). In theory single imports should
1344- // always block globs, even if they are not yet resolved, so that this kind of
1345- // self-inconsistent resolution never happens.
1346- // Re-enable the assert when the issue is fixed.
1347- // assert!(result[ns].get().is_err());
1321+ if let Some ( initial_res) = initial_res {
1322+ if res != initial_res && !this. issue_145575_hack_applied {
1323+ span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1324+ }
1325+ } else if this. privacy_errors . is_empty ( ) {
1326+ this. dcx ( )
1327+ . create_err ( CannotDetermineImportResolution { span : import. span } )
1328+ . emit ( ) ;
13481329 }
13491330 }
1331+ Err ( ..) => {
1332+ // FIXME: This assert may fire if public glob is later shadowed by a private
1333+ // single import (see test `issue-55884-2.rs`). In theory single imports should
1334+ // always block globs, even if they are not yet resolved, so that this kind of
1335+ // self-inconsistent resolution never happens.
1336+ // Re-enable the assert when the issue is fixed.
1337+ // assert!(result[ns].get().is_err());
1338+ }
13501339 }
13511340 } ) ;
13521341
13531342 if all_ns_err {
13541343 let mut all_ns_failed = true ;
13551344 self . per_ns ( |this, ns| {
1356- if !type_ns_only || ns == TypeNS {
1357- let binding = this. cm ( ) . resolve_ident_in_module (
1358- module,
1359- ident,
1360- ns,
1361- & import. parent_scope ,
1362- Some ( finalize) ,
1363- None ,
1364- None ,
1365- ) ;
1366- if binding. is_ok ( ) {
1367- all_ns_failed = false ;
1368- }
1345+ let binding = this. cm ( ) . resolve_ident_in_module (
1346+ module,
1347+ ident,
1348+ ns,
1349+ & import. parent_scope ,
1350+ Some ( finalize) ,
1351+ None ,
1352+ None ,
1353+ ) ;
1354+ if binding. is_ok ( ) {
1355+ all_ns_failed = false ;
13691356 }
13701357 } ) ;
13711358
0 commit comments