visitor.block_indent = shape.indent;
visitor.last_pos = self.span().lo();
visitor.visit_item(self);
- Some(visitor.buffer)
+ Some(visitor.buffer.to_owned())
}
}
";",
|branch| branch.span.lo(),
|branch| branch.span.hi(),
- |branch| branch.rewrite(context, arm_shape, multi_branch_style),
+ |branch| match branch.rewrite(context, arm_shape, multi_branch_style) {
+ Some(v) => Some(v),
+ // if the rewrite returned None because a macro could not be rewritten, then return the
+ // original body
+ None if *context.macro_rewrite_failure.borrow() == true => {
+ Some(context.snippet(branch.body).trim().to_string())
+ }
+ None => None,
+ },
context.snippet_provider.span_after(span, "{"),
span.hi(),
false,
} else {
Some(get_prefix_space_width(context, &line))
};
+
let line = if veto_trim || (kind.is_string() && !line.ends_with('\\')) {
veto_trim = kind.is_string() && !line.ends_with('\\');
trimmed = false;
line.trim().to_owned()
};
trimmed_lines.push((trimmed, line, prefix_space_width));
- prefix_space_width
+
+ // when computing the minimum, do not consider lines within a string
+ match kind {
+ FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
+ _ => prefix_space_width,
+ }
}).min()?;
Some(
let new_indent_width = indent.width() + original_indent_width
.saturating_sub(min_prefix_space_width);
let new_indent = Indent::from_width(context.config, new_indent_width);
- format!("{}{}", new_indent.to_string(context.config), line.trim())
+ format!("{}{}", new_indent.to_string(context.config), line)
}
None => String::new(),
},