Skip to content

Commit 94df4f8

Browse files
committed
Move the empty path_list handling into rewrite_use_list()
1 parent fa242a5 commit 94df4f8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/imports.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,8 @@ fn rewrite_view_path_prefix(
157157
}
158158

159159
impl Rewrite for ast::ViewPath {
160-
// Returns an empty string when the ViewPath is empty (like foo::bar::{})
161160
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
162161
match self.node {
163-
ast::ViewPath_::ViewPathList(_, ref path_list) if path_list.is_empty() => {
164-
Some(String::new())
165-
}
166162
ast::ViewPath_::ViewPathList(ref path, ref path_list) => {
167163
rewrite_use_list(shape, path, path_list, self.span, context)
168164
}
@@ -263,12 +259,11 @@ impl<'a> FmtVisitor<'a> {
263259
.offset_left(vis.len() + 4)
264260
.and_then(|shape| shape.sub_width(1))
265261
.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() =>
269265
{
270-
rewrite_path(&self.get_context(), PathContext::Import, None, path, shape)
271-
.map(|path_str| format!("{}::{{}}", path_str))
266+
Some("".into())
272267
}
273268
_ => vp.rewrite(&self.get_context(), shape),
274269
});
@@ -400,7 +395,7 @@ impl<'a> Ord for ImportItem<'a> {
400395
}
401396

402397
// 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.
404399
fn rewrite_use_list(
405400
shape: Shape,
406401
path: &ast::Path,
@@ -418,7 +413,10 @@ fn rewrite_use_list(
418413
));
419414

420415
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+
}
422420
1 => return Some(rewrite_single_use_list(path_str, &path_list[0])),
423421
_ => (),
424422
}

0 commit comments

Comments
 (0)