DefinitiveListTactic::Mixed
},
};
+ let mut ends_with_newline = tactic.ends_with_newline(context.config.array_layout());
if context.config.array_horizontal_layout_threshold() > 0 &&
items.len() > context.config.array_horizontal_layout_threshold()
{
tactic = DefinitiveListTactic::Mixed;
+ ends_with_newline = false;
if context.config.array_layout() == IndentStyle::Block {
nested_shape = try_opt!(
shape
SeparatorTactic::Vertical
},
shape: nested_shape,
- ends_with_newline: false,
+ ends_with_newline: ends_with_newline,
config: context.config,
};
let list_str = try_opt!(write_list(&items, &fmt));
.and_then(|item| item.post_comment.as_ref())
.map_or(false, |s| s.trim().starts_with("//"));
- let (indent, trailing_comma, end_with_newline) = match context.config.fn_args_layout() {
- IndentStyle::Block if fits_in_one_line => (
- indent.block_indent(context.config),
- SeparatorTactic::Never,
- true,
- ),
+ let (indent, trailing_comma) = match context.config.fn_args_layout() {
+ IndentStyle::Block if fits_in_one_line => {
+ (indent.block_indent(context.config), SeparatorTactic::Never)
+ }
IndentStyle::Block => (
indent.block_indent(context.config),
context.config.trailing_comma(),
- true,
),
IndentStyle::Visual if last_line_ends_with_comment => {
- (arg_indent, context.config.trailing_comma(), true)
+ (arg_indent, context.config.trailing_comma())
}
- IndentStyle::Visual => (arg_indent, SeparatorTactic::Never, false),
+ IndentStyle::Visual => (arg_indent, SeparatorTactic::Never),
};
let tactic = definitive_tactic(
trailing_comma
},
shape: Shape::legacy(budget, indent),
- ends_with_newline: end_with_newline,
+ ends_with_newline: tactic.ends_with_newline(context.config.fn_args_layout()),
config: context.config,
};
let item_vec = items.collect::<Vec<_>>();
let tactic = definitive_tactic(&item_vec, ListTactic::HorizontalVertical, one_line_budget);
- let ends_with_newline = context.config.generics_indent() == IndentStyle::Block &&
- tactic == DefinitiveListTactic::Vertical;
let fmt = ListFormatting {
tactic: tactic,
separator: ",",
context.config.trailing_comma()
},
shape: shape,
- ends_with_newline: ends_with_newline,
+ ends_with_newline: tactic.ends_with_newline(context.config.generics_indent()),
config: context.config,
};
separator: ",",
trailing_separator: comma_tactic,
shape: Shape::legacy(budget, offset),
- ends_with_newline: true,
+ ends_with_newline: tactic.ends_with_newline(context.config.where_pred_indent()),
config: context.config,
};
let preds_str = try_opt!(write_list(&item_vec, &fmt));
Mixed,
}
+impl DefinitiveListTactic {
+ pub fn ends_with_newline(&self, indent_style: IndentStyle) -> bool {
+ match indent_style {
+ IndentStyle::Block => *self != DefinitiveListTactic::Horizontal,
+ IndentStyle::Visual => false,
+ }
+ }
+}
+
pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> DefinitiveListTactic
where
I: IntoIterator<Item = T> + Clone,
// Now that we know how we will layout, we can decide for sure if there
// will be a trailing separator.
- let trailing_separator = needs_trailing_separator(formatting.trailing_separator, tactic);
+ let mut trailing_separator = needs_trailing_separator(formatting.trailing_separator, tactic);
let mut result = String::new();
let cloned_items = items.clone();
let mut iter = items.into_iter().enumerate().peekable();
let inner_item = try_opt!(item.item.as_ref());
let first = i == 0;
let last = iter.peek().is_none();
- let separate = !last || trailing_separator;
+ let mut separate = !last || trailing_separator;
let item_sep_len = if separate { sep_len } else { 0 };
// Item string may be multi-line. Its length (used for block comment alignment)
result.push('\n');
result.push_str(indent_str);
line_len = 0;
+ if tactic == DefinitiveListTactic::Mixed && formatting.ends_with_newline {
+ if last {
+ separate = true;
+ } else {
+ trailing_separator = true;
+ }
+ }
}
if line_len > 0 {
context.config.trailing_comma()
},
shape: list_shape,
- ends_with_newline: false,
+ ends_with_newline: tactic.ends_with_newline(context.config.fn_call_style()),
config: context.config,
};
fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
- adipiscing: Adipiscing, elit: Elit
+ adipiscing: Adipiscing, elit: Elit,
);
fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: onsectetur,
- adipiscing: Adipiscing, elit: Elit
+ adipiscing: Adipiscing, elit: Elit,
) {
// body
}
// Test compressed layout of args.
fn foo(
a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd,
- e: Eeeeeeeeeeeeeeeeeee
+ e: Eeeeeeeeeeeeeeeeeee,
) {
foo();
}
impl Foo {
fn foo(
self, a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc,
- d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee
+ d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee,
) {
foo();
}
C,
D,
// pre comment
- E, /* last comment */
+ E, // last comment
) -> &SomeType,
{
arg(a, b, c, d, e)
C,
D,
// pre comment
- E, /* last comment */
+ E, // last comment
) -> &SomeType,
{
arg(a, b, c, d, e)
y: String, // comment 3
z: Foo,
// comment
- ... /* comment 2 */
+ ... // comment 2
),
}