use codemap::SpanUtils;
use comment::FindUncommented;
-use expr::{can_be_overflowed_expr, rewrite_pair, rewrite_unary_prefix, wrap_struct_field,
- PairParts};
-use lists::{itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
- struct_lit_tactic, write_list};
+use expr::{can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field};
+use lists::{
+ itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, struct_lit_tactic,
+ write_list,
+};
use macros::{rewrite_macro, MacroPosition};
use overflow;
+use pairs::{rewrite_pair, PairParts};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use spanned::Spanned;
use types::{rewrite_path, PathContext};
-use utils::{format_mutability, mk_sp};
+use utils::{format_mutability, mk_sp, rewrite_ident};
/// Returns true if the given pattern is short. A short pattern is defined by the following grammer:
///
BindingMode::ByValue(mutability) => ("", mutability),
};
let mut_infix = format_mutability(mutability);
- let id_str = ident.node.to_string();
+ let id_str = rewrite_ident(context, ident);
let sub_pat = match *sub_pat {
Some(ref p) => {
// 3 - ` @ `.
}
}
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
- let infix = match *end_kind {
+ let infix = match end_kind.node {
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",
RangeEnd::Included(RangeSyntax::DotDotEq) => "..=",
RangeEnd::Excluded => "..",
rewrite_pair(
&**lhs,
&**rhs,
- PairParts::new("", &infix, ""),
+ PairParts::infix(&infix),
context,
shape,
SeparatorPlace::Front,
let prefix = prefix.iter().map(|p| p.rewrite(context, shape));
let slice_pat = slice_pat
.as_ref()
- .map(|p| Some(format!("{}..", p.rewrite(context, shape)?)));
+ .and_then(|p| p.rewrite(context, shape))
+ .map(|rw| Some(format!("{}..", if rw == "_" { "" } else { &rw })));
let suffix = suffix.iter().map(|p| p.rewrite(context, shape));
// Munge them together.
let pats = pats?;
// Unwrap all the sub-strings and join them with commas.
- let result = if context.config.spaces_within_parens_and_brackets() {
- format!("[ {} ]", pats.join(", "))
- } else {
- format!("[{}]", pats.join(", "))
- };
- Some(result)
+ Some(format!("[{}]", pats.join(", ")))
}
PatKind::Struct(ref path, ref fields, ellipsis) => {
rewrite_struct_pat(path, fields, ellipsis, self.span, context, shape)
}
PatKind::Mac(ref mac) => rewrite_macro(mac, None, context, shape, MacroPosition::Pat),
- PatKind::Paren(ref pat) => pat.rewrite(context, shape.offset_left(1)?.sub_width(1)?)
+ PatKind::Paren(ref pat) => pat
+ .rewrite(context, shape.offset_left(1)?.sub_width(1)?)
.map(|inner_pat| format!("({})", inner_pat)),
}
}
if ellipsis {
if fields_str.contains('\n') || fields_str.len() > one_line_width {
// Add a missing trailing comma.
- if fmt.trailing_separator == SeparatorTactic::Never {
+ if context.config.trailing_comma() == SeparatorTactic::Never {
fields_str.push_str(",");
}
fields_str.push_str("\n");
} else {
if !fields_str.is_empty() {
// there are preceding struct fields being matched on
- if fmt.tactic == DefinitiveListTactic::Vertical {
+ if tactic == DefinitiveListTactic::Vertical {
// if the tactic is Vertical, write_list already added a trailing ,
fields_str.push_str(" ");
} else {
pat
} else {
let pat_str = pat?;
- let id_str = self.ident.to_string();
+ let id_str = rewrite_ident(context, self.ident);
let one_line_width = id_str.len() + 2 + pat_str.len();
if one_line_width <= shape.width {
Some(format!("{}: {}", id_str, pat_str))
}) {
suffix_len += 1;
- if item.pre_comment.is_some() || item.post_comment.is_some() {
+ if item.has_comment() {
break;
}
}