@@ -157,12 +157,8 @@ fn rewrite_view_path_prefix(
157
157
}
158
158
159
159
impl Rewrite for ast:: ViewPath {
160
- // Returns an empty string when the ViewPath is empty (like foo::bar::{})
161
160
fn rewrite ( & self , context : & RewriteContext , shape : Shape ) -> Option < String > {
162
161
match self . node {
163
- ast:: ViewPath_ :: ViewPathList ( _, ref path_list) if path_list. is_empty ( ) => {
164
- Some ( String :: new ( ) )
165
- }
166
162
ast:: ViewPath_ :: ViewPathList ( ref path, ref path_list) => {
167
163
rewrite_use_list ( shape, path, path_list, self . span , context)
168
164
}
@@ -250,13 +246,27 @@ impl<'a> FmtVisitor<'a> {
250
246
self . last_pos = pos_after_last_use_item;
251
247
}
252
248
253
- pub fn format_import ( & mut self , vis : & ast:: Visibility , vp : & ast:: ViewPath , span : Span ) {
249
+ pub fn format_import (
250
+ & mut self ,
251
+ vis : & ast:: Visibility ,
252
+ vp : & ast:: ViewPath ,
253
+ span : Span ,
254
+ attrs : & [ ast:: Attribute ] ,
255
+ ) {
254
256
let vis = utils:: format_visibility ( vis) ;
255
257
// 4 = `use `, 1 = `;`
256
258
let rw = Shape :: indented ( self . block_indent , self . config )
257
259
. offset_left ( vis. len ( ) + 4 )
258
260
. and_then ( |shape| shape. sub_width ( 1 ) )
259
- . and_then ( |shape| vp. rewrite ( & self . get_context ( ) , shape) ) ;
261
+ . and_then ( |shape| match vp. node {
262
+ // If we have an empty path list with no attributes, we erase it
263
+ ast:: ViewPath_ :: ViewPathList ( _, ref path_list)
264
+ if path_list. is_empty ( ) && attrs. is_empty ( ) =>
265
+ {
266
+ Some ( "" . into ( ) )
267
+ }
268
+ _ => vp. rewrite ( & self . get_context ( ) , shape) ,
269
+ } ) ;
260
270
match rw {
261
271
Some ( ref s) if s. is_empty ( ) => {
262
272
// Format up to last newline
@@ -385,7 +395,7 @@ impl<'a> Ord for ImportItem<'a> {
385
395
}
386
396
387
397
// Pretty prints a multi-item import.
388
- // Assumes that path_list.len() > 0 .
398
+ // If the path list is empty, it leaves the braces empty .
389
399
fn rewrite_use_list (
390
400
shape : Shape ,
391
401
path : & ast:: Path ,
@@ -403,7 +413,10 @@ fn rewrite_use_list(
403
413
) ) ;
404
414
405
415
match path_list. len ( ) {
406
- 0 => unreachable ! ( ) ,
416
+ 0 => {
417
+ return rewrite_path ( context, PathContext :: Import , None , path, shape)
418
+ . map ( |path_str| format ! ( "{}::{{}}" , path_str) ) ;
419
+ }
407
420
1 => return Some ( rewrite_single_use_list ( path_str, & path_list[ 0 ] ) ) ,
408
421
_ => ( ) ,
409
422
}
0 commit comments