@@ -72,8 +72,6 @@ pub(crate) enum ImportKind<'ra> {
7272 target : Ident ,
7373 /// Name declarations introduced by the import.
7474 decls : PerNS < CmCell < PendingDecl < ' ra > > > ,
75- /// `true` for `...::{self [as target]}` imports, `false` otherwise.
76- type_ns_only : bool ,
7775 /// Did this import result from a nested import? i.e. `use foo::{bar, baz};`
7876 nested : bool ,
7977 /// The ID of the `UseTree` that imported this `Import`.
@@ -114,7 +112,7 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
114112 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
115113 use ImportKind :: * ;
116114 match self {
117- Single { source, target, decls, type_ns_only , nested, id, .. } => f
115+ Single { source, target, decls, nested, id, .. } => f
118116 . debug_struct ( "Single" )
119117 . field ( "source" , source)
120118 . field ( "target" , target)
@@ -123,7 +121,6 @@ impl<'ra> std::fmt::Debug for ImportKind<'ra> {
123121 "decls" ,
124122 & decls. clone ( ) . map ( |b| b. into_inner ( ) . decl ( ) . map ( |_| format_args ! ( ".." ) ) ) ,
125123 )
126- . field ( "type_ns_only" , type_ns_only)
127124 . field ( "nested" , nested)
128125 . field ( "id" , id)
129126 . finish ( ) ,
@@ -987,10 +984,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
987984 } ;
988985
989986 import. imported_module . set_unchecked ( Some ( module) ) ;
990- let ( source, target, bindings, type_ns_only) = match import. kind {
991- ImportKind :: Single { source, target, ref decls, type_ns_only, .. } => {
992- ( source, target, decls, type_ns_only)
993- }
987+ let ( source, target, bindings) = match import. kind {
988+ ImportKind :: Single { source, target, ref decls, .. } => ( source, target, decls) ,
994989 ImportKind :: Glob { .. } => {
995990 self . get_mut_unchecked ( ) . resolve_glob_import ( import) ;
996991 return 0 ;
@@ -1000,64 +995,62 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
1000995
1001996 let mut indeterminate_count = 0 ;
1002997 self . per_ns_cm ( |mut this, ns| {
1003- if !type_ns_only || ns == TypeNS {
1004- if bindings[ ns] . get ( ) != PendingDecl :: Pending {
1005- return ;
1006- } ;
1007- let binding_result = this. reborrow ( ) . maybe_resolve_ident_in_module (
1008- module,
1009- source,
1010- ns,
1011- & import. parent_scope ,
1012- Some ( import) ,
1013- ) ;
1014- let parent = import. parent_scope . module ;
1015- let binding = match binding_result {
1016- Ok ( binding) => {
1017- if binding. is_assoc_item ( )
1018- && !this. tcx . features ( ) . import_trait_associated_functions ( )
1019- {
1020- feature_err (
1021- this. tcx . sess ,
1022- sym:: import_trait_associated_functions,
1023- import. span ,
1024- "`use` associated items of traits is unstable" ,
1025- )
1026- . emit ( ) ;
1027- }
1028- // We need the `target`, `source` can be extracted.
1029- let import_decl = this. new_import_decl ( binding, import) ;
1030- this. get_mut_unchecked ( ) . plant_decl_into_local_module (
1031- IdentKey :: new ( target) ,
998+ if bindings[ ns] . get ( ) != PendingDecl :: Pending {
999+ return ;
1000+ } ;
1001+ let binding_result = this. reborrow ( ) . maybe_resolve_ident_in_module (
1002+ module,
1003+ source,
1004+ ns,
1005+ & import. parent_scope ,
1006+ Some ( import) ,
1007+ ) ;
1008+ let parent = import. parent_scope . module ;
1009+ let binding = match binding_result {
1010+ Ok ( binding) => {
1011+ if binding. is_assoc_item ( )
1012+ && !this. tcx . features ( ) . import_trait_associated_functions ( )
1013+ {
1014+ feature_err (
1015+ this. tcx . sess ,
1016+ sym:: import_trait_associated_functions,
1017+ import. span ,
1018+ "`use` associated items of traits is unstable" ,
1019+ )
1020+ . emit ( ) ;
1021+ }
1022+ // We need the `target`, `source` can be extracted.
1023+ let import_decl = this. new_import_decl ( binding, import) ;
1024+ this. get_mut_unchecked ( ) . plant_decl_into_local_module (
1025+ IdentKey :: new ( target) ,
1026+ target. span ,
1027+ ns,
1028+ import_decl,
1029+ ) ;
1030+ PendingDecl :: Ready ( Some ( import_decl) )
1031+ }
1032+ Err ( Determinacy :: Determined ) => {
1033+ // Don't remove underscores from `single_imports`, they were never added.
1034+ if target. name != kw:: Underscore {
1035+ let key = BindingKey :: new ( IdentKey :: new ( target) , ns) ;
1036+ this. get_mut_unchecked ( ) . update_local_resolution (
1037+ parent,
1038+ key,
10321039 target. span ,
1033- ns,
1034- import_decl,
1040+ false ,
1041+ |_, resolution| {
1042+ resolution. single_imports . swap_remove ( & import) ;
1043+ } ,
10351044 ) ;
1036- PendingDecl :: Ready ( Some ( import_decl) )
10371045 }
1038- Err ( Determinacy :: Determined ) => {
1039- // Don't remove underscores from `single_imports`, they were never added.
1040- if target. name != kw:: Underscore {
1041- let key = BindingKey :: new ( IdentKey :: new ( target) , ns) ;
1042- this. get_mut_unchecked ( ) . update_local_resolution (
1043- parent,
1044- key,
1045- target. span ,
1046- false ,
1047- |_, resolution| {
1048- resolution. single_imports . swap_remove ( & import) ;
1049- } ,
1050- ) ;
1051- }
1052- PendingDecl :: Ready ( None )
1053- }
1054- Err ( Determinacy :: Undetermined ) => {
1055- indeterminate_count += 1 ;
1056- PendingDecl :: Pending
1057- }
1058- } ;
1059- bindings[ ns] . set_unchecked ( binding) ;
1060- }
1046+ PendingDecl :: Ready ( None )
1047+ }
1048+ Err ( Determinacy :: Undetermined ) => {
1049+ indeterminate_count += 1 ;
1050+ PendingDecl :: Pending
1051+ }
1052+ } ;
1053+ bindings[ ns] . set_unchecked ( binding) ;
10611054 } ) ;
10621055
10631056 indeterminate_count
@@ -1196,10 +1189,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11961189 PathResult :: Indeterminate => unreachable ! ( ) ,
11971190 } ;
11981191
1199- let ( ident, target, bindings, type_ns_only, import_id) = match import. kind {
1200- ImportKind :: Single { source, target, ref decls, type_ns_only, id, .. } => {
1201- ( source, target, decls, type_ns_only, id)
1202- }
1192+ let ( ident, target, bindings, import_id) = match import. kind {
1193+ ImportKind :: Single { source, target, ref decls, id, .. } => ( source, target, decls, id) ,
12031194 ImportKind :: Glob { ref max_vis, id } => {
12041195 if import. module_path . len ( ) <= 1 {
12051196 // HACK(eddyb) `lint_if_path_starts_with_module` needs at least
@@ -1267,86 +1258,78 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12671258
12681259 let mut all_ns_err = true ;
12691260 self . per_ns ( |this, ns| {
1270- if !type_ns_only || ns == TypeNS {
1271- let binding = this. cm ( ) . resolve_ident_in_module (
1272- module,
1273- ident,
1274- ns,
1275- & import. parent_scope ,
1276- Some ( Finalize {
1277- report_private : false ,
1278- import_vis : Some ( import. vis ) ,
1279- ..finalize
1280- } ) ,
1281- bindings[ ns] . get ( ) . decl ( ) ,
1282- Some ( import) ,
1283- ) ;
1261+ let binding = this. cm ( ) . resolve_ident_in_module (
1262+ module,
1263+ ident,
1264+ ns,
1265+ & import. parent_scope ,
1266+ Some ( Finalize { report_private : false , import_vis : Some ( import. vis ) , ..finalize } ) ,
1267+ bindings[ ns] . get ( ) . decl ( ) ,
1268+ Some ( import) ,
1269+ ) ;
12841270
1285- match binding {
1286- Ok ( binding) => {
1287- // Consistency checks, analogous to `finalize_macro_resolutions`.
1288- let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1289- let initial_binding = binding. import_source ( ) ;
1290- all_ns_err = false ;
1291- if target. name == kw:: Underscore
1292- && initial_binding. is_extern_crate ( )
1293- && !initial_binding. is_import ( )
1294- {
1295- let used = if import. module_path . is_empty ( ) {
1296- Used :: Scope
1297- } else {
1298- Used :: Other
1299- } ;
1300- this. record_use ( ident, binding, used) ;
1301- }
1302- initial_binding. res ( )
1303- } ) ;
1304- let res = binding. res ( ) ;
1305- let has_ambiguity_error =
1306- this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1307- if res == Res :: Err || has_ambiguity_error {
1308- this. dcx ( )
1309- . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1310- return ;
1311- }
1312- if let Some ( initial_res) = initial_res {
1313- if res != initial_res && !this. issue_145575_hack_applied {
1314- span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1315- }
1316- } else if this. privacy_errors . is_empty ( ) {
1317- this. dcx ( )
1318- . create_err ( CannotDetermineImportResolution { span : import. span } )
1319- . emit ( ) ;
1271+ match binding {
1272+ Ok ( binding) => {
1273+ // Consistency checks, analogous to `finalize_macro_resolutions`.
1274+ let initial_res = bindings[ ns] . get ( ) . decl ( ) . map ( |binding| {
1275+ let initial_binding = binding. import_source ( ) ;
1276+ all_ns_err = false ;
1277+ if target. name == kw:: Underscore
1278+ && initial_binding. is_extern_crate ( )
1279+ && !initial_binding. is_import ( )
1280+ {
1281+ let used = if import. module_path . is_empty ( ) {
1282+ Used :: Scope
1283+ } else {
1284+ Used :: Other
1285+ } ;
1286+ this. record_use ( ident, binding, used) ;
13201287 }
1288+ initial_binding. res ( )
1289+ } ) ;
1290+ let res = binding. res ( ) ;
1291+ let has_ambiguity_error =
1292+ this. ambiguity_errors . iter ( ) . any ( |error| error. warning . is_none ( ) ) ;
1293+ if res == Res :: Err || has_ambiguity_error {
1294+ this. dcx ( )
1295+ . span_delayed_bug ( import. span , "some error happened for an import" ) ;
1296+ return ;
13211297 }
1322- Err ( ..) => {
1323- // FIXME: This assert may fire if public glob is later shadowed by a private
1324- // single import (see test `issue-55884-2.rs`). In theory single imports should
1325- // always block globs, even if they are not yet resolved, so that this kind of
1326- // self-inconsistent resolution never happens.
1327- // Re-enable the assert when the issue is fixed.
1328- // assert!(result[ns].get().is_err());
1298+ if let Some ( initial_res) = initial_res {
1299+ if res != initial_res && !this. issue_145575_hack_applied {
1300+ span_bug ! ( import. span, "inconsistent resolution for an import" ) ;
1301+ }
1302+ } else if this. privacy_errors . is_empty ( ) {
1303+ this. dcx ( )
1304+ . create_err ( CannotDetermineImportResolution { span : import. span } )
1305+ . emit ( ) ;
13291306 }
13301307 }
1308+ Err ( ..) => {
1309+ // FIXME: This assert may fire if public glob is later shadowed by a private
1310+ // single import (see test `issue-55884-2.rs`). In theory single imports should
1311+ // always block globs, even if they are not yet resolved, so that this kind of
1312+ // self-inconsistent resolution never happens.
1313+ // Re-enable the assert when the issue is fixed.
1314+ // assert!(result[ns].get().is_err());
1315+ }
13311316 }
13321317 } ) ;
13331318
13341319 if all_ns_err {
13351320 let mut all_ns_failed = true ;
13361321 self . per_ns ( |this, ns| {
1337- if !type_ns_only || ns == TypeNS {
1338- let binding = this. cm ( ) . resolve_ident_in_module (
1339- module,
1340- ident,
1341- ns,
1342- & import. parent_scope ,
1343- Some ( finalize) ,
1344- None ,
1345- None ,
1346- ) ;
1347- if binding. is_ok ( ) {
1348- all_ns_failed = false ;
1349- }
1322+ let binding = this. cm ( ) . resolve_ident_in_module (
1323+ module,
1324+ ident,
1325+ ns,
1326+ & import. parent_scope ,
1327+ Some ( finalize) ,
1328+ None ,
1329+ None ,
1330+ ) ;
1331+ if binding. is_ok ( ) {
1332+ all_ns_failed = false ;
13501333 }
13511334 } ) ;
13521335
0 commit comments