@@ -135,7 +135,7 @@ impl<'a> std::fmt::Debug for ImportKind<'a> {
135135
136136/// One import.
137137#[ derive( Debug , Clone ) ]
138- pub ( crate ) struct Import < ' a > {
138+ pub ( crate ) struct ImportData < ' a > {
139139 pub kind : ImportKind < ' a > ,
140140
141141 /// Node ID of the "root" use item -- this is always the same as `ImportKind`'s `id`
@@ -172,7 +172,9 @@ pub(crate) struct Import<'a> {
172172 pub used : Cell < bool > ,
173173}
174174
175- impl < ' a > Import < ' a > {
175+ pub ( crate ) type Import < ' a > = Interned < ' a , ImportData < ' a > > ;
176+
177+ impl < ' a > ImportData < ' a > {
176178 pub ( crate ) fn is_glob ( & self ) -> bool {
177179 matches ! ( self . kind, ImportKind :: Glob { .. } )
178180 }
@@ -214,7 +216,7 @@ impl<'a> Import<'a> {
214216pub ( crate ) struct NameResolution < ' a > {
215217 /// Single imports that may define the name in the namespace.
216218 /// Imports are arena-allocated, so it's ok to use pointers as keys.
217- pub single_imports : FxHashSet < Interned < ' a , Import < ' a > > > ,
219+ pub single_imports : FxHashSet < Import < ' a > > ,
218220 /// The least shadowable known binding for this name, or None if there are no known bindings.
219221 pub binding : Option < NameBinding < ' a > > ,
220222 pub shadowed_glob : Option < NameBinding < ' a > > ,
@@ -231,10 +233,6 @@ impl<'a> NameResolution<'a> {
231233 }
232234 } )
233235 }
234-
235- pub ( crate ) fn add_single_import ( & mut self , import : & ' a Import < ' a > ) {
236- self . single_imports . insert ( Interned :: new_unchecked ( import) ) ;
237- }
238236}
239237
240238/// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved
@@ -250,27 +248,20 @@ struct UnresolvedImportError {
250248
251249// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
252250// are permitted for backward-compatibility under a deprecation lint.
253- fn pub_use_of_private_extern_crate_hack ( import : & Import < ' _ > , binding : NameBinding < ' _ > ) -> bool {
251+ fn pub_use_of_private_extern_crate_hack ( import : Import < ' _ > , binding : NameBinding < ' _ > ) -> bool {
254252 match ( & import. kind , & binding. kind ) {
255- (
256- ImportKind :: Single { .. } ,
257- NameBindingKind :: Import {
258- import : Import { kind : ImportKind :: ExternCrate { .. } , .. } ,
259- ..
260- } ,
261- ) => import. expect_vis ( ) . is_public ( ) ,
253+ ( ImportKind :: Single { .. } , NameBindingKind :: Import { import : binding_import, .. } ) => {
254+ matches ! ( binding_import. kind, ImportKind :: ExternCrate { .. } )
255+ && import. expect_vis ( ) . is_public ( )
256+ }
262257 _ => false ,
263258 }
264259}
265260
266261impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
267262 /// Given a binding and an import that resolves to it,
268263 /// return the corresponding binding defined by the import.
269- pub ( crate ) fn import (
270- & self ,
271- binding : NameBinding < ' a > ,
272- import : & ' a Import < ' a > ,
273- ) -> NameBinding < ' a > {
264+ pub ( crate ) fn import ( & self , binding : NameBinding < ' a > , import : Import < ' a > ) -> NameBinding < ' a > {
274265 let import_vis = import. expect_vis ( ) . to_def_id ( ) ;
275266 let vis = if binding. vis . is_at_least ( import_vis, self . tcx )
276267 || pub_use_of_private_extern_crate_hack ( import, binding)
@@ -411,7 +402,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
411402 None => continue ,
412403 } ;
413404 if self . is_accessible_from ( binding. vis , scope) {
414- let imported_binding = self . import ( binding, import) ;
405+ let imported_binding = self . import ( binding, * import) ;
415406 let key = BindingKey { ident, ..key } ;
416407 let _ = self . try_define ( import. parent_scope . module , key, imported_binding) ;
417408 }
@@ -422,7 +413,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
422413
423414 // Define a dummy resolution containing a `Res::Err` as a placeholder for a failed
424415 // or indeterminate resolution, also mark such failed imports as used to avoid duplicate diagnostics.
425- fn import_dummy_binding ( & mut self , import : & ' a Import < ' a > , is_indeterminate : bool ) {
416+ fn import_dummy_binding ( & mut self , import : Import < ' a > , is_indeterminate : bool ) {
426417 if let ImportKind :: Single { target, ref target_bindings, .. } = import. kind {
427418 if !( is_indeterminate || target_bindings. iter ( ) . all ( |binding| binding. get ( ) . is_none ( ) ) )
428419 {
@@ -460,7 +451,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
460451 prev_indeterminate_count = indeterminate_count;
461452 indeterminate_count = 0 ;
462453 for import in mem:: take ( & mut self . indeterminate_imports ) {
463- let import_indeterminate_count = self . resolve_import ( & import) ;
454+ let import_indeterminate_count = self . resolve_import ( import) ;
464455 indeterminate_count += import_indeterminate_count;
465456 match import_indeterminate_count {
466457 0 => self . determined_imports . push ( import) ,
@@ -609,7 +600,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
609600 }
610601 }
611602
612- fn throw_unresolved_import_error ( & mut self , errors : Vec < ( & Import < ' _ > , UnresolvedImportError ) > ) {
603+ fn throw_unresolved_import_error ( & mut self , errors : Vec < ( Import < ' _ > , UnresolvedImportError ) > ) {
613604 if errors. is_empty ( ) {
614605 return ;
615606 }
@@ -701,7 +692,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
701692 ///
702693 /// Meanwhile, if resolve successful, the resolved bindings are written
703694 /// into the module.
704- fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> usize {
695+ fn resolve_import ( & mut self , import : Import < ' a > ) -> usize {
705696 debug ! (
706697 "(resolving import for module) resolving import `{}::...` in `{}`" ,
707698 Segment :: names_to_string( & import. module_path) ,
@@ -781,7 +772,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
781772 }
782773 let key = BindingKey :: new ( target, ns) ;
783774 this. update_resolution ( parent, key, |_, resolution| {
784- resolution. single_imports . remove ( & Interned :: new_unchecked ( import) ) ;
775+ resolution. single_imports . remove ( & import) ;
785776 } ) ;
786777 }
787778 }
@@ -795,7 +786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
795786 ///
796787 /// Optionally returns an unresolved import error. This error is buffered and used to
797788 /// consolidate multiple unresolved import errors into a single diagnostic.
798- fn finalize_import ( & mut self , import : & ' a Import < ' a > ) -> Option < UnresolvedImportError > {
789+ fn finalize_import ( & mut self , import : Import < ' a > ) -> Option < UnresolvedImportError > {
799790 let orig_vis = import. vis . take ( ) ;
800791 let ignore_binding = match & import. kind {
801792 ImportKind :: Single { target_bindings, .. } => target_bindings[ TypeNS ] . get ( ) ,
@@ -1239,7 +1230,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12391230 fn check_for_redundant_imports (
12401231 & mut self ,
12411232 ident : Ident ,
1242- import : & ' a Import < ' a > ,
1233+ import : Import < ' a > ,
12431234 source_bindings : & PerNS < Cell < Result < NameBinding < ' a > , Determinacy > > > ,
12441235 target_bindings : & PerNS < Cell < Option < NameBinding < ' a > > > > ,
12451236 target : Ident ,
@@ -1302,7 +1293,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13021293 }
13031294 }
13041295
1305- fn resolve_glob_import ( & mut self , import : & ' a Import < ' a > ) {
1296+ fn resolve_glob_import ( & mut self , import : Import < ' a > ) {
13061297 // This function is only called for glob imports.
13071298 let ImportKind :: Glob { id, is_prelude, .. } = import. kind else { unreachable ! ( ) } ;
13081299
0 commit comments