@@ -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
}
@@ -263,12 +259,11 @@ impl<'a> FmtVisitor<'a> {
263
259
. offset_left ( vis. len ( ) + 4 )
264
260
. and_then ( |shape| shape. sub_width ( 1 ) )
265
261
. and_then ( |shape| match vp. node {
266
- // If we have an empty path with attributes attached , we want to skip erasing it
267
- ast:: ViewPath_ :: ViewPathList ( ref path , ref path_list)
268
- if path_list. is_empty ( ) && ! attrs. is_empty ( ) =>
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 ( ) =>
269
265
{
270
- rewrite_path ( & self . get_context ( ) , PathContext :: Import , None , path, shape)
271
- . map ( |path_str| format ! ( "{}::{{}}" , path_str) )
266
+ Some ( "" . into ( ) )
272
267
}
273
268
_ => vp. rewrite ( & self . get_context ( ) , shape) ,
274
269
} ) ;
@@ -400,7 +395,7 @@ impl<'a> Ord for ImportItem<'a> {
400
395
}
401
396
402
397
// Pretty prints a multi-item import.
403
- // Assumes that path_list.len() > 0 .
398
+ // If the path list is empty, it leaves the braces empty .
404
399
fn rewrite_use_list (
405
400
shape : Shape ,
406
401
path : & ast:: Path ,
@@ -418,7 +413,10 @@ fn rewrite_use_list(
418
413
) ) ;
419
414
420
415
match path_list. len ( ) {
421
- 0 => unreachable ! ( ) ,
416
+ 0 => {
417
+ return rewrite_path ( context, PathContext :: Import , None , path, shape)
418
+ . map ( |path_str| format ! ( "{}::{{}}" , path_str) ) ;
419
+ }
422
420
1 => return Some ( rewrite_single_use_list ( path_str, & path_list[ 0 ] ) ) ,
423
421
_ => ( ) ,
424
422
}
0 commit comments