@@ -135,7 +135,7 @@ impl<'a> std::fmt::Debug for ImportKind<'a> {
135
135
136
136
/// One import.
137
137
#[ derive( Debug , Clone ) ]
138
- pub ( crate ) struct Import < ' a > {
138
+ pub ( crate ) struct ImportData < ' a > {
139
139
pub kind : ImportKind < ' a > ,
140
140
141
141
/// 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> {
172
172
pub used : Cell < bool > ,
173
173
}
174
174
175
- impl < ' a > Import < ' a > {
175
+ pub ( crate ) type Import < ' a > = Interned < ' a , ImportData < ' a > > ;
176
+
177
+ impl < ' a > ImportData < ' a > {
176
178
pub ( crate ) fn is_glob ( & self ) -> bool {
177
179
matches ! ( self . kind, ImportKind :: Glob { .. } )
178
180
}
@@ -214,7 +216,7 @@ impl<'a> Import<'a> {
214
216
pub ( crate ) struct NameResolution < ' a > {
215
217
/// Single imports that may define the name in the namespace.
216
218
/// 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 > > ,
218
220
/// The least shadowable known binding for this name, or None if there are no known bindings.
219
221
pub binding : Option < NameBinding < ' a > > ,
220
222
pub shadowed_glob : Option < NameBinding < ' a > > ,
@@ -231,10 +233,6 @@ impl<'a> NameResolution<'a> {
231
233
}
232
234
} )
233
235
}
234
-
235
- pub ( crate ) fn add_single_import ( & mut self , import : & ' a Import < ' a > ) {
236
- self . single_imports . insert ( Interned :: new_unchecked ( import) ) ;
237
- }
238
236
}
239
237
240
238
/// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved
@@ -250,27 +248,20 @@ struct UnresolvedImportError {
250
248
251
249
// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
252
250
// 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 {
254
252
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
+ }
262
257
_ => false ,
263
258
}
264
259
}
265
260
266
261
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
267
262
/// Given a binding and an import that resolves to it,
268
263
/// 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 > {
274
265
let import_vis = import. expect_vis ( ) . to_def_id ( ) ;
275
266
let vis = if binding. vis . is_at_least ( import_vis, self . tcx )
276
267
|| pub_use_of_private_extern_crate_hack ( import, binding)
@@ -411,7 +402,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
411
402
None => continue ,
412
403
} ;
413
404
if self . is_accessible_from ( binding. vis , scope) {
414
- let imported_binding = self . import ( binding, import) ;
405
+ let imported_binding = self . import ( binding, * import) ;
415
406
let key = BindingKey { ident, ..key } ;
416
407
let _ = self . try_define ( import. parent_scope . module , key, imported_binding) ;
417
408
}
@@ -422,7 +413,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
422
413
423
414
// Define a dummy resolution containing a `Res::Err` as a placeholder for a failed
424
415
// 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 ) {
426
417
if let ImportKind :: Single { target, ref target_bindings, .. } = import. kind {
427
418
if !( is_indeterminate || target_bindings. iter ( ) . all ( |binding| binding. get ( ) . is_none ( ) ) )
428
419
{
@@ -460,7 +451,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
460
451
prev_indeterminate_count = indeterminate_count;
461
452
indeterminate_count = 0 ;
462
453
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) ;
464
455
indeterminate_count += import_indeterminate_count;
465
456
match import_indeterminate_count {
466
457
0 => self . determined_imports . push ( import) ,
@@ -609,7 +600,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
609
600
}
610
601
}
611
602
612
- fn throw_unresolved_import_error ( & mut self , errors : Vec < ( & Import < ' _ > , UnresolvedImportError ) > ) {
603
+ fn throw_unresolved_import_error ( & mut self , errors : Vec < ( Import < ' _ > , UnresolvedImportError ) > ) {
613
604
if errors. is_empty ( ) {
614
605
return ;
615
606
}
@@ -701,7 +692,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
701
692
///
702
693
/// Meanwhile, if resolve successful, the resolved bindings are written
703
694
/// into the module.
704
- fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> usize {
695
+ fn resolve_import ( & mut self , import : Import < ' a > ) -> usize {
705
696
debug ! (
706
697
"(resolving import for module) resolving import `{}::...` in `{}`" ,
707
698
Segment :: names_to_string( & import. module_path) ,
@@ -781,7 +772,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
781
772
}
782
773
let key = BindingKey :: new ( target, ns) ;
783
774
this. update_resolution ( parent, key, |_, resolution| {
784
- resolution. single_imports . remove ( & Interned :: new_unchecked ( import) ) ;
775
+ resolution. single_imports . remove ( & import) ;
785
776
} ) ;
786
777
}
787
778
}
@@ -795,7 +786,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
795
786
///
796
787
/// Optionally returns an unresolved import error. This error is buffered and used to
797
788
/// 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 > {
799
790
let orig_vis = import. vis . take ( ) ;
800
791
let ignore_binding = match & import. kind {
801
792
ImportKind :: Single { target_bindings, .. } => target_bindings[ TypeNS ] . get ( ) ,
@@ -1239,7 +1230,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1239
1230
fn check_for_redundant_imports (
1240
1231
& mut self ,
1241
1232
ident : Ident ,
1242
- import : & ' a Import < ' a > ,
1233
+ import : Import < ' a > ,
1243
1234
source_bindings : & PerNS < Cell < Result < NameBinding < ' a > , Determinacy > > > ,
1244
1235
target_bindings : & PerNS < Cell < Option < NameBinding < ' a > > > > ,
1245
1236
target : Ident ,
@@ -1302,7 +1293,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1302
1293
}
1303
1294
}
1304
1295
1305
- fn resolve_glob_import ( & mut self , import : & ' a Import < ' a > ) {
1296
+ fn resolve_glob_import ( & mut self , import : Import < ' a > ) {
1306
1297
// This function is only called for glob imports.
1307
1298
let ImportKind :: Glob { id, is_prelude, .. } = import. kind else { unreachable ! ( ) } ;
1308
1299
0 commit comments