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