16
16
use macros:: { InvocationData , ParentScope , LegacyScope } ;
17
17
use resolve_imports:: ImportDirective ;
18
18
use resolve_imports:: ImportDirectiveSubclass :: { self , GlobImport , SingleImport } ;
19
- use { Module , ModuleData , ModuleKind , NameBinding , NameBindingKind , ToNameBinding } ;
19
+ use { Module , ModuleData , ModuleKind , NameBinding , NameBindingKind , Segment , ToNameBinding } ;
20
20
use { ModuleOrUniformRoot , PerNS , Resolver , ResolverArenas , ExternPreludeEntry } ;
21
21
use Namespace :: { self , TypeNS , ValueNS , MacroNS } ;
22
22
use { resolve_error, resolve_struct_error, ResolutionError } ;
@@ -122,7 +122,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
122
122
use_tree : & ast:: UseTree ,
123
123
id : NodeId ,
124
124
vis : ty:: Visibility ,
125
- parent_prefix : & [ Ident ] ,
125
+ parent_prefix : & [ Segment ] ,
126
126
mut uniform_paths_canary_emitted : bool ,
127
127
nested : bool ,
128
128
item : & Item ,
@@ -139,10 +139,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
139
139
self . session . features_untracked ( ) . uniform_paths ;
140
140
141
141
let prefix_iter = || parent_prefix. iter ( ) . cloned ( )
142
- . chain ( use_tree. prefix . segments . iter ( ) . map ( |seg| seg. ident ) ) ;
142
+ . chain ( use_tree. prefix . segments . iter ( ) . map ( |seg| seg. into ( ) ) ) ;
143
143
let prefix_start = prefix_iter ( ) . next ( ) ;
144
- let starts_with_non_keyword = prefix_start. map_or ( false , |( ident , _ ) | {
145
- !ident. is_path_segment_keyword ( )
144
+ let starts_with_non_keyword = prefix_start. map_or ( false , |seg | {
145
+ !seg . ident . is_path_segment_keyword ( )
146
146
} ) ;
147
147
148
148
// Imports are resolved as global by default, prepend `CrateRoot`,
@@ -156,7 +156,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
156
156
} ;
157
157
let root = if inject_crate_root {
158
158
let span = use_tree. prefix . span . shrink_to_lo ( ) ;
159
- Some ( Ident :: new ( keywords:: CrateRoot . name ( ) , span) )
159
+ Some ( Segment :: from_ident ( Ident :: new ( keywords:: CrateRoot . name ( ) , span) ) )
160
160
} else {
161
161
None
162
162
} ;
@@ -202,13 +202,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
202
202
let source = prefix_start. unwrap ( ) ;
203
203
204
204
// Helper closure to emit a canary with the given base path.
205
- let emit = |this : & mut Self , base : Option < ( Ident , Option < NodeId > ) > | {
205
+ let emit = |this : & mut Self , base : Option < Segment > | {
206
206
let subclass = SingleImport {
207
207
target : Ident {
208
208
name : keywords:: Underscore . name ( ) . gensymed ( ) ,
209
- span : source. 0 . span ,
209
+ span : source. ident . span ,
210
210
} ,
211
- source : source. 0 ,
211
+ source : source. ident ,
212
212
result : PerNS {
213
213
type_ns : Cell :: new ( Err ( Undetermined ) ) ,
214
214
value_ns : Cell :: new ( Err ( Undetermined ) ) ,
@@ -219,7 +219,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
219
219
this. add_import_directive (
220
220
base. into_iter ( ) . collect ( ) ,
221
221
subclass. clone ( ) ,
222
- source. 0 . span ,
222
+ source. ident . span ,
223
223
id,
224
224
root_use_tree. span ,
225
225
root_id,
@@ -230,15 +230,18 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
230
230
} ;
231
231
232
232
// A single simple `self::x` canary.
233
- emit ( self , Some ( ( Ident {
234
- name : keywords:: SelfValue . name ( ) ,
235
- span : source. 0 . span ,
236
- } , source. 1 ) ) ) ;
233
+ emit ( self , Some ( Segment {
234
+ ident : Ident {
235
+ name : keywords:: SelfValue . name ( ) ,
236
+ span : source. ident . span ,
237
+ } ,
238
+ id : source. id
239
+ } ) ) ;
237
240
238
241
// One special unprefixed canary per block scope around
239
242
// the import, to detect items unreachable by `self::x`.
240
243
let orig_current_module = self . current_module ;
241
- let mut span = source. 0 . span . modern ( ) ;
244
+ let mut span = source. ident . span . modern ( ) ;
242
245
loop {
243
246
match self . current_module . kind {
244
247
ModuleKind :: Block ( ..) => emit ( self , None ) ,
@@ -265,11 +268,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
265
268
266
269
if nested {
267
270
// Correctly handle `self`
268
- if source. 0 . name == keywords:: SelfValue . name ( ) {
271
+ if source. ident . name == keywords:: SelfValue . name ( ) {
269
272
type_ns_only = true ;
270
273
271
- let empty_prefix = module_path. last ( ) . map_or ( true , |( ident , _ ) | {
272
- ident. name == keywords:: CrateRoot . name ( )
274
+ let empty_prefix = module_path. last ( ) . map_or ( true , |seg | {
275
+ seg . ident . name == keywords:: CrateRoot . name ( )
273
276
} ) ;
274
277
if empty_prefix {
275
278
resolve_error (
@@ -284,20 +287,20 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
284
287
// Replace `use foo::self;` with `use foo;`
285
288
source = module_path. pop ( ) . unwrap ( ) ;
286
289
if rename. is_none ( ) {
287
- ident = source. 0 ;
290
+ ident = source. ident ;
288
291
}
289
292
}
290
293
} else {
291
294
// Disallow `self`
292
- if source. 0 . name == keywords:: SelfValue . name ( ) {
295
+ if source. ident . name == keywords:: SelfValue . name ( ) {
293
296
resolve_error ( self ,
294
297
use_tree. span ,
295
298
ResolutionError :: SelfImportsOnlyAllowedWithin ) ;
296
299
}
297
300
298
301
// Disallow `use $crate;`
299
- if source. 0 . name == keywords:: DollarCrate . name ( ) && module_path. is_empty ( ) {
300
- let crate_root = self . resolve_crate_root ( source. 0 ) ;
302
+ if source. ident . name == keywords:: DollarCrate . name ( ) && module_path. is_empty ( ) {
303
+ let crate_root = self . resolve_crate_root ( source. ident ) ;
301
304
let crate_name = match crate_root. kind {
302
305
ModuleKind :: Def ( _, name) => name,
303
306
ModuleKind :: Block ( ..) => unreachable ! ( ) ,
@@ -307,11 +310,14 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
307
310
// while the current crate doesn't have a valid `crate_name`.
308
311
if crate_name != keywords:: Invalid . name ( ) {
309
312
// `crate_name` should not be interpreted as relative.
310
- module_path. push ( ( Ident {
311
- name : keywords:: CrateRoot . name ( ) ,
312
- span : source. 0 . span ,
313
- } , Some ( self . session . next_node_id ( ) ) ) ) ;
314
- source. 0 . name = crate_name;
313
+ module_path. push ( Segment {
314
+ ident : Ident {
315
+ name : keywords:: CrateRoot . name ( ) ,
316
+ span : source. ident . span ,
317
+ } ,
318
+ id : Some ( self . session . next_node_id ( ) ) ,
319
+ } ) ;
320
+ source. ident . name = crate_name;
315
321
}
316
322
if rename. is_none ( ) {
317
323
ident. name = crate_name;
@@ -332,7 +338,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
332
338
333
339
let subclass = SingleImport {
334
340
target : ident,
335
- source : source. 0 ,
341
+ source : source. ident ,
336
342
result : PerNS {
337
343
type_ns : Cell :: new ( Err ( Undetermined ) ) ,
338
344
value_ns : Cell :: new ( Err ( Undetermined ) ) ,
@@ -392,17 +398,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
392
398
e. emit ( ) ;
393
399
}
394
400
395
- let prefix = ast:: Path {
396
- segments : module_path. into_iter ( )
397
- . map ( |( ident, id) | {
398
- let mut seg = ast:: PathSegment :: from_ident ( ident) ;
399
- seg. id = id. expect ( "Missing node id" ) ;
400
- seg
401
- } )
402
- . collect ( ) ,
403
- span : path. span ,
404
- } ;
405
-
406
401
for & ( ref tree, id) in items {
407
402
self . build_reduced_graph_for_use_tree (
408
403
root_use_tree,
0 commit comments