@@ -142,8 +142,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
142
142
if source. name == keywords:: SelfValue . name ( ) {
143
143
type_ns_only = true ;
144
144
145
- let last_segment = * module_path. last ( ) . unwrap ( ) ;
146
- if last_segment. name == keywords:: CrateRoot . name ( ) {
145
+ let empty_prefix = module_path. last ( ) . map_or ( true , |ident| {
146
+ ident. name == keywords:: CrateRoot . name ( )
147
+ } ) ;
148
+ if empty_prefix {
147
149
resolve_error (
148
150
self ,
149
151
use_tree. span ,
@@ -154,10 +156,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
154
156
}
155
157
156
158
// Replace `use foo::self;` with `use foo;`
157
- let _ = module_path. pop ( ) ;
158
- source = last_segment;
159
+ source = module_path. pop ( ) . unwrap ( ) ;
159
160
if rename. is_none ( ) {
160
- ident = last_segment ;
161
+ ident = source ;
161
162
}
162
163
}
163
164
} else {
@@ -169,7 +170,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
169
170
}
170
171
171
172
// Disallow `use $crate;`
172
- if source. name == keywords:: DollarCrate . name ( ) && path . segments . len ( ) == 1 {
173
+ if source. name == keywords:: DollarCrate . name ( ) && module_path . is_empty ( ) {
173
174
let crate_root = self . resolve_crate_root ( source) ;
174
175
let crate_name = match crate_root. kind {
175
176
ModuleKind :: Def ( _, name) => name,
@@ -179,6 +180,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
179
180
// in `source` breaks `src/test/compile-fail/import-crate-var.rs`,
180
181
// while the current crate doesn't have a valid `crate_name`.
181
182
if crate_name != keywords:: Invalid . name ( ) {
183
+ // `crate_name` should not be interpreted as relative.
184
+ module_path. push ( Ident {
185
+ name : keywords:: CrateRoot . name ( ) ,
186
+ span : source. span ,
187
+ } ) ;
182
188
source. name = crate_name;
183
189
}
184
190
if rename. is_none ( ) {
@@ -283,9 +289,18 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
283
289
284
290
match item. node {
285
291
ItemKind :: Use ( ref use_tree) => {
292
+ let uniform_paths =
293
+ self . session . rust_2018 ( ) &&
294
+ self . session . features_untracked ( ) . uniform_paths ;
286
295
// Imports are resolved as global by default, add starting root segment.
296
+ let root = if !uniform_paths {
297
+ use_tree. prefix . make_root ( )
298
+ } else {
299
+ // Except when `#![feature(uniform_paths)]` is on.
300
+ None
301
+ } ;
287
302
let prefix = ast:: Path {
288
- segments : use_tree . prefix . make_root ( ) . into_iter ( ) . collect ( ) ,
303
+ segments : root . into_iter ( ) . collect ( ) ,
289
304
span : use_tree. span ,
290
305
} ;
291
306
0 commit comments