@@ -142,8 +142,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
142142 if source. name == keywords:: SelfValue . name ( ) {
143143 type_ns_only = true ;
144144
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 {
147149 resolve_error (
148150 self ,
149151 use_tree. span ,
@@ -154,10 +156,9 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
154156 }
155157
156158 // Replace `use foo::self;` with `use foo;`
157- let _ = module_path. pop ( ) ;
158- source = last_segment;
159+ source = module_path. pop ( ) . unwrap ( ) ;
159160 if rename. is_none ( ) {
160- ident = last_segment ;
161+ ident = source ;
161162 }
162163 }
163164 } else {
@@ -169,7 +170,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
169170 }
170171
171172 // 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 ( ) {
173174 let crate_root = self . resolve_crate_root ( source) ;
174175 let crate_name = match crate_root. kind {
175176 ModuleKind :: Def ( _, name) => name,
@@ -179,6 +180,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
179180 // in `source` breaks `src/test/compile-fail/import-crate-var.rs`,
180181 // while the current crate doesn't have a valid `crate_name`.
181182 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+ } ) ;
182188 source. name = crate_name;
183189 }
184190 if rename. is_none ( ) {
@@ -283,9 +289,18 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
283289
284290 match item. node {
285291 ItemKind :: Use ( ref use_tree) => {
292+ let uniform_paths =
293+ self . session . rust_2018 ( ) &&
294+ self . session . features_untracked ( ) . uniform_paths ;
286295 // 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+ } ;
287302 let prefix = ast:: Path {
288- segments : use_tree . prefix . make_root ( ) . into_iter ( ) . collect ( ) ,
303+ segments : root . into_iter ( ) . collect ( ) ,
289304 span : use_tree. span ,
290305 } ;
291306
0 commit comments