@@ -71,8 +71,6 @@ pub(crate) enum ImportKind<'ra> {
7171 target : Ident ,
7272 /// Name declarations introduced by the import.
7373 decls : PerNS < CmCell < PendingDecl < ' ra > > > ,
74- /// `true` for `...::{self [as target]}` imports, `false` otherwise.
75- type_ns_only : bool ,
7674 /// Did this import result from a nested import? i.e. `use foo::{bar, baz};`
7775 nested : bool ,
7876 /// The ID of the `UseTree` that imported this `Import`.
@@ -113,7 +111,7 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
113111 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
114112 use ImportKind :: * ;
115113 match self {
116- Single { source, target, decls, type_ns_only , nested, id, .. } => f
114+ Single { source, target, decls, nested, id, .. } => f
117115 . debug_struct ( "Single" )
118116 . field ( "source" , source)
119117 . field ( "target" , target)
@@ -122,7 +120,6 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
122120 "decls" ,
123121 & decls. clone ( ) . map ( |b| b. into_inner ( ) . decl ( ) . map ( |_| format_args ! ( ".." ) ) ) ,
124122 )
125- . field ( "type_ns_only" , type_ns_only)
126123 . field ( "nested" , nested)
127124 . field ( "id" , id)
128125 . 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
@@ -1213,10 +1206,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12131206 PathResult :: Indeterminate => unreachable ! ( ) ,
12141207 } ;
12151208
1216- let ( ident, target, bindings, type_ns_only, import_id) = match import. kind {
1217- ImportKind :: Single { source, target, ref decls, type_ns_only, id, .. } => {
1218- ( source, target, decls, type_ns_only, id)
1219- }
1209+ let ( ident, target, bindings, import_id) = match import. kind {
1210+ ImportKind :: Single { source, target, ref decls, id, .. } => ( source, target, decls, id) ,
12201211 ImportKind :: Glob { ref max_vis, id } => {
12211212 if import. module_path . len ( ) <= 1 {
12221213 // HACK(eddyb) `lint_if_path_starts_with_module` needs at least
@@ -1284,86 +1275,82 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12841275
12851276 let mut all_ns_err = true ;
12861277 self . per_ns ( |this, ns| {
1287- if !type_ns_only || ns == TypeNS {
1288- let binding = this. cm ( ) . resolve_ident_in_module (
1289- module,
1290- ident,
1291- ns,
1292- & import. parent_scope ,
1293- Some ( Finalize {
1294- report_private : false ,
1295- import : Some ( import. summary ( ) ) ,
1296- ..finalize
1297- } ) ,
1298- bindings[ ns] . get ( ) . decl ( ) ,
1299- Some ( import) ,
1300- ) ;
1278+ let binding = this. cm ( ) . resolve_ident_in_module (
1279+ module,
1280+ ident,
1281+ ns,
1282+ & import. parent_scope ,
1283+ Some ( Finalize {
1284+ report_private : false ,
1285+ import : Some ( import. summary ( ) ) ,
1286+ ..finalize
1287+ } ) ,
1288+ bindings[ ns] . get ( ) . decl ( ) ,
1289+ Some ( import) ,
1290+ ) ;
13011291
1302- match binding {
1303- Ok ( binding) => {
1304- // Consistency checks, analogous to `finalize_macro_resolutions`.
1305- let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1306- let initial_binding = binding. import_source ( ) ;
1307- all_ns_err = false ;
1308- if target. name == kw:: Underscore
1309- && initial_binding. is_extern_crate ( )
1310- && !initial_binding. is_import ( )
1311- {
1312- let used = if import. module_path . is_empty ( ) {
1313- Used :: Scope
1314- } else {
1315- Used :: Other
1316- } ;
1317- this. record_use ( ident, binding, used) ;
1318- }
1319- initial_binding. res ( )
1320- } ) ;
1321- let res = binding. res ( ) ;
1322- let has_ambiguity_error =
1323- this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1324- if res == Res :: Err || has_ambiguity_error {
1325- this. dcx ( )
1326- . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1327- return ;
1328- }
1329- if let Some ( initial_res) = initial_res {
1330- if res != initial_res && !this. issue_145575_hack_applied {
1331- span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1332- }
1333- } else if this. privacy_errors . is_empty ( ) {
1334- this. dcx ( )
1335- . create_err ( CannotDetermineImportResolution { span : import. span } )
1336- . emit ( ) ;
1292+ match binding {
1293+ Ok ( binding) => {
1294+ // Consistency checks, analogous to `finalize_macro_resolutions`.
1295+ let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1296+ let initial_binding = binding. import_source ( ) ;
1297+ all_ns_err = false ;
1298+ if target. name == kw:: Underscore
1299+ && initial_binding. is_extern_crate ( )
1300+ && !initial_binding. is_import ( )
1301+ {
1302+ let used = if import. module_path . is_empty ( ) {
1303+ Used :: Scope
1304+ } else {
1305+ Used :: Other
1306+ } ;
1307+ this. record_use ( ident, binding, used) ;
13371308 }
1309+ initial_binding. res ( )
1310+ } ) ;
1311+ let res = binding. res ( ) ;
1312+ let has_ambiguity_error =
1313+ this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1314+ if res == Res :: Err || has_ambiguity_error {
1315+ this. dcx ( )
1316+ . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1317+ return ;
13381318 }
1339- Err ( ..) => {
1340- // FIXME: This assert may fire if public glob is later shadowed by a private
1341- // single import (see test `issue-55884-2.rs`). In theory single imports should
1342- // always block globs, even if they are not yet resolved, so that this kind of
1343- // self-inconsistent resolution never happens.
1344- // Re-enable the assert when the issue is fixed.
1345- // assert!(result[ns].get().is_err());
1319+ if let Some ( initial_res) = initial_res {
1320+ if res != initial_res && !this. issue_145575_hack_applied {
1321+ span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1322+ }
1323+ } else if this. privacy_errors . is_empty ( ) {
1324+ this. dcx ( )
1325+ . create_err ( CannotDetermineImportResolution { span : import. span } )
1326+ . emit ( ) ;
13461327 }
13471328 }
1329+ Err ( ..) => {
1330+ // FIXME: This assert may fire if public glob is later shadowed by a private
1331+ // single import (see test `issue-55884-2.rs`). In theory single imports should
1332+ // always block globs, even if they are not yet resolved, so that this kind of
1333+ // self-inconsistent resolution never happens.
1334+ // Re-enable the assert when the issue is fixed.
1335+ // assert!(result[ns].get().is_err());
1336+ }
13481337 }
13491338 } ) ;
13501339
13511340 if all_ns_err {
13521341 let mut all_ns_failed = true ;
13531342 self . per_ns ( |this, ns| {
1354- if !type_ns_only || ns == TypeNS {
1355- let binding = this. cm ( ) . resolve_ident_in_module (
1356- module,
1357- ident,
1358- ns,
1359- & import. parent_scope ,
1360- Some ( finalize) ,
1361- None ,
1362- None ,
1363- ) ;
1364- if binding. is_ok ( ) {
1365- all_ns_failed = false ;
1366- }
1343+ let binding = this. cm ( ) . resolve_ident_in_module (
1344+ module,
1345+ ident,
1346+ ns,
1347+ & import. parent_scope ,
1348+ Some ( finalize) ,
1349+ None ,
1350+ None ,
1351+ ) ;
1352+ if binding. is_ok ( ) {
1353+ all_ns_failed = false ;
13671354 }
13681355 } ) ;
13691356
0 commit comments