use std::cmp;
+use config::lists::*;
use syntax::ast;
use syntax::codemap::{BytePos, Span};
use comment::{combine_strs_with_missing_comments, contains_comment};
use expr::rewrite_field;
use items::{rewrite_struct_field, rewrite_struct_field_prefix};
-use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListTactic, Separator,
- SeparatorPlace};
+use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use rewrite::{Rewrite, RewriteContext};
use shape::{Indent, Shape};
use spanned::Spanned;
-use utils::{contains_skip, is_attributes_extendable, mk_sp};
+use utils::{contains_skip, is_attributes_extendable, mk_sp, rewrite_ident};
pub trait AlignedItem {
fn skip(&self) -> bool;
fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
let attrs_str = self.attrs.rewrite(context, shape)?;
- let name = &self.ident.node.to_string();
+ let name = rewrite_ident(context, self.ident);
let missing_span = if self.attrs.is_empty() {
mk_sp(self.span.lo(), self.span.lo())
} else {
let rest_lo = rest[0].get_span().lo();
let missing_span = mk_sp(init_hi, rest_lo);
let missing_span = mk_sp(
- context.codemap.span_after(missing_span, ","),
+ context.snippet_provider.span_after(missing_span, ","),
missing_span.hi(),
);
let rest_span = mk_sp(init_last_pos, span.hi());
let rest_str = rewrite_with_alignment(rest, context, shape, rest_span, one_line_width)?;
Some(
- result + spaces + "\n"
+ result
+ + spaces
+ + "\n"
+ &shape
.indent
.block_indent(context.config)
- .to_string(context.config) + &rest_str,
+ .to_string(context.config)
+ + &rest_str,
)
}
}
Some(field_str.len())
}
})
- })
- .fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
+ }).fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
(Some((max_len, min_len)), Some(len)) => {
Some((cmp::max(max_len, len), cmp::min(min_len, len)))
}
_ => None,
- })
- .unwrap_or((0, 0))
+ }).unwrap_or((0, 0))
}
fn rewrite_aligned_items_inner<T: AlignedItem>(
let item_shape = Shape::indented(item_indent, context.config).sub_width(1)?;
let (mut field_prefix_max_width, field_prefix_min_width) =
struct_field_prefix_max_min_width(context, fields, item_shape);
- let max_diff = field_prefix_max_width
- .checked_sub(field_prefix_min_width)
- .unwrap_or(0);
+ let max_diff = field_prefix_max_width.saturating_sub(field_prefix_min_width);
if max_diff > context.config.struct_field_align_threshold() {
field_prefix_max_width = 0;
}
let items = itemize_list(
- context.codemap,
+ context.snippet_provider,
fields.iter(),
"}",
",",
one_line_width,
);
- let fmt = ListFormatting {
- tactic,
- separator: ",",
- trailing_separator: context.config.trailing_comma(),
- separator_place: SeparatorPlace::Back,
- shape: item_shape,
- ends_with_newline: true,
- preserve_newline: true,
- config: context.config,
- };
+ let fmt = ListFormatting::new(item_shape, context.config)
+ .tactic(tactic)
+ .trailing_separator(context.config.trailing_comma())
+ .preserve_newline(true);
write_list(&items, &fmt)
}