fn format_foreign_item(&mut self, item: &ast::ForeignItem) {
- let shape = Shape::indented(self.block_indent, self.config);
- let rewrite = item.rewrite(&self.get_context(), shape);
+ let rewrite = item.rewrite(&self.get_context(), self.shape());
self.push_rewrite(item.span(), rewrite);
self.last_pos = item.span.hi;
}
""
};
- format_expr(
- &e,
- ExprType::Statement,
- &self.get_context(),
- Shape::indented(self.block_indent, self.config),
- ).map(|s| s + suffix)
+ format_expr(&e, ExprType::Statement, &self.get_context(), self.shape())
+ .map(|s| s + suffix)
.or_else(|| Some(self.snippet(e.span)))
}
- None => stmt.rewrite(
- &self.get_context(),
- Shape::indented(self.block_indent, self.config),
- ),
+ None => stmt.rewrite(&self.get_context(), self.shape()),
}
} else {
None
false,
);
- let shape = Shape::indented(self.block_indent, self.config)
- .sub_width(2)
- .unwrap();
+ let shape = self.shape().sub_width(2).unwrap();
let fmt = ListFormatting {
tactic: DefinitiveListTactic::Vertical,
separator: ",",
let context = self.get_context();
let indent = self.block_indent;
- let shape = Shape::indented(indent, self.config);
+ let shape = self.shape();
let attrs_str = try_opt!(field.node.attrs.rewrite(&context, shape));
let lo = field
.node
}
impl<'a> FmtVisitor<'a> {
+ pub fn shape(&self) -> Shape {
+ Shape::indented(self.block_indent, self.config)
+ }
+
fn visit_stmt(&mut self, stmt: &ast::Stmt) {
debug!(
"visit_stmt: {:?} {:?}",
if let Some(first_stmt) = b.stmts.first() {
let attr_lo = inner_attrs
.and_then(|attrs| {
- utils::inner_attributes(attrs)
- .first()
- .map(|attr| attr.span.lo)
+ inner_attributes(attrs).first().map(|attr| attr.span.lo)
})
.or_else(|| {
// Attributes for an item in a statement position
let mut unindent_comment = self.is_if_else_block && !b.stmts.is_empty();
if unindent_comment {
let end_pos = source!(self, b.span).hi - brace_compensation - remove_len;
- let snippet = self.get_context().snippet(mk_sp(self.last_pos, end_pos));
+ let snippet = self.snippet(mk_sp(self.last_pos, end_pos));
unindent_comment = snippet.contains("//") || snippet.contains("/*");
}
// FIXME: we should compress any newlines here to just one
self.push_rewrite(item.span, None);
return;
}
- } else if utils::contains_skip(&item.attrs) {
+ } else if contains_skip(&item.attrs) {
// Module is not inline, but should be skipped.
return;
} else {
}
ast::ItemKind::Impl(..) => {
self.format_missing_with_indent(source!(self, item.span).lo);
- let snippet = self.get_context().snippet(item.span);
+ let snippet = self.snippet(item.span);
let where_span_end = snippet
.find_uncommented("{")
.map(|x| (BytePos(x as u32)) + source!(self, item.span).lo);
skip_out_of_file_lines_range_visitor!(self, mac.span);
// 1 = ;
- let shape = Shape::indented(self.block_indent, self.config)
- .sub_width(1)
- .unwrap();
+ let shape = self.shape().sub_width(1).unwrap();
let rewrite = rewrite_macro(mac, ident, &self.get_context(), shape, pos);
self.push_rewrite(mac.span, rewrite);
}
// Returns true if we should skip the following item.
pub fn visit_attrs(&mut self, attrs: &[ast::Attribute], style: ast::AttrStyle) -> bool {
- if utils::contains_skip(attrs) {
+ if contains_skip(attrs) {
return true;
}
return false;
}
- let rewrite = attrs.rewrite(
- &self.get_context(),
- Shape::indented(self.block_indent, self.config),
- );
+ let rewrite = attrs.rewrite(&self.get_context(), self.shape());
let span = mk_sp(attrs[0].span.lo, attrs[attrs.len() - 1].span.hi);
self.push_rewrite(span, rewrite);