Add flag to the ListFormatting struct for nested imports

This commit is contained in:
Josh Chase
2018-06-19 11:28:58 -04:00
parent 2077855e00
commit ee5ff2d9e8
12 changed files with 20 additions and 1 deletions
+1
View File
@@ -247,6 +247,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
shape: item_shape,
ends_with_newline: false,
preserve_newline: false,
nested: false,
config: context.config,
};
let item_str = write_list(&item_vec, &fmt)?;
+1
View File
@@ -260,6 +260,7 @@ fn rewrite_closure_fn_decl(
shape: arg_shape,
ends_with_newline: false,
preserve_newline: true,
nested: false,
config: context.config,
};
let list_str = write_list(&item_vec, &fmt)?;
+2
View File
@@ -1338,6 +1338,7 @@ pub fn rewrite_multiple_patterns(
shape,
ends_with_newline: false,
preserve_newline: false,
nested: false,
config: context.config,
};
write_list(&items, &fmt)
@@ -1902,6 +1903,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T>(
shape,
ends_with_newline: false,
preserve_newline: false,
nested: false,
config: context.config,
};
let list_str = write_list(&item_vec, &fmt)?;
+1
View File
@@ -727,6 +727,7 @@ fn rewrite_nested_use_tree(
shape: nested_shape,
ends_with_newline,
preserve_newline: true,
nested: has_nested_list,
config: context.config,
};
+4
View File
@@ -533,6 +533,7 @@ fn format_variant_list(
shape,
ends_with_newline: true,
preserve_newline: true,
nested: false,
config: self.config,
};
@@ -2307,6 +2308,7 @@ enum ArgumentKind<'a> {
shape: Shape::legacy(budget, indent),
ends_with_newline: tactic.ends_with_newline(context.config.indent_style()),
preserve_newline: true,
nested: false,
config: context.config,
};
@@ -2494,6 +2496,7 @@ fn rewrite_where_clause_rfc_style(
shape: clause_shape,
ends_with_newline: true,
preserve_newline: true,
nested: false,
config: context.config,
};
let preds_str = write_list(&items.collect::<Vec<_>>(), &fmt)?;
@@ -2607,6 +2610,7 @@ fn rewrite_where_clause(
shape: Shape::legacy(budget, offset),
ends_with_newline: tactic.ends_with_newline(context.config.indent_style()),
preserve_newline: true,
nested: false,
config: context.config,
};
let preds_str = write_list(&item_vec, &fmt)?;
+5 -1
View File
@@ -34,6 +34,8 @@ pub struct ListFormatting<'a> {
pub ends_with_newline: bool,
// Remove newlines between list elements for expressions.
pub preserve_newline: bool,
// Nested import lists get some special handling for the "Mixed" list type
pub nested: bool,
pub config: &'a Config,
}
@@ -288,7 +290,8 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
// 1 is space between separator and item.
if (line_len > 0 && line_len + 1 + total_width > formatting.shape.width)
|| prev_item_had_post_comment
|| (prev_item_is_nested_import || (!first && inner_item.contains("::")))
|| (formatting.nested
&& (prev_item_is_nested_import || (!first && inner_item.contains("::"))))
{
result.push('\n');
result.push_str(indent_str);
@@ -824,6 +827,7 @@ pub fn struct_lit_formatting<'a>(
shape,
ends_with_newline,
preserve_newline: true,
nested: false,
config: context.config,
}
}
+1
View File
@@ -399,6 +399,7 @@ pub fn rewrite_macro_def(
shape: arm_shape,
ends_with_newline: true,
preserve_newline: true,
nested: false,
config: context.config,
};
+1
View File
@@ -224,6 +224,7 @@ fn rewrite_match_arms(
shape: arm_shape,
ends_with_newline: true,
preserve_newline: true,
nested: false,
config: context.config,
};
+1
View File
@@ -388,6 +388,7 @@ fn rewrite_items(&self) -> Option<(bool, String)> {
_ => false,
},
preserve_newline: false,
nested: false,
config: self.context.config,
};
+1
View File
@@ -77,6 +77,7 @@ fn wrap_reorderable_items(
shape,
ends_with_newline: true,
preserve_newline: false,
nested: false,
config: context.config,
};
+1
View File
@@ -366,6 +366,7 @@ enum ArgumentKind<T>
shape: list_shape,
ends_with_newline: tactic.ends_with_newline(context.config.indent_style()),
preserve_newline: true,
nested: false,
config: context.config,
};
+1
View File
@@ -252,6 +252,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
shape: item_shape,
ends_with_newline: true,
preserve_newline: true,
nested: false,
config: context.config,
};
write_list(&items, &fmt)