use strings::string_buffer::StringBuffer;
-use Indent;
+use {Indent, Shape};
use utils;
use codemap::{LineRangeUtils, SpanUtils};
use config::Config;
use rewrite::{Rewrite, RewriteContext};
use comment::rewrite_comment;
use macros::{rewrite_macro, MacroPosition};
-use items::{rewrite_static, rewrite_associated_type, rewrite_type_alias, format_impl, format_trait};
+use items::{rewrite_static, rewrite_associated_type, rewrite_associated_impl_type,
+ rewrite_type_alias, format_impl, format_trait};
fn is_use_item(item: &ast::Item) -> bool {
match item.node {
ast::StmtKind::Expr(..) |
ast::StmtKind::Semi(..) => {
let rewrite = stmt.rewrite(&self.get_context(),
- self.config.max_width - self.block_indent.width(),
- self.block_indent);
+ Shape::legacy(self.config.max_width -
+ self.block_indent.width(),
+ self.block_indent));
self.push_rewrite(stmt.span, rewrite);
}
ast::StmtKind::Mac(ref mac) => {
item.span,
indent,
None)
- .map(|s| match *def {
- ast::VariantData::Tuple(..) => s + ";",
- _ => s,
- })
+ .map(|s| match *def {
+ ast::VariantData::Tuple(..) => s + ";",
+ _ => s,
+ })
};
self.push_rewrite(item.span, rewrite);
}
ty,
mutability,
Some(expr),
+ self.block_indent,
&self.get_context());
self.push_rewrite(item.span, rewrite);
}
ty,
ast::Mutability::Immutable,
Some(expr),
+ self.block_indent,
&self.get_context());
self.push_rewrite(item.span, rewrite);
}
ty,
ast::Mutability::Immutable,
expr_opt.as_ref(),
+ self.block_indent,
&self.get_context());
self.push_rewrite(ti.span, rewrite);
}
ty,
ast::Mutability::Immutable,
Some(expr),
+ self.block_indent,
&self.get_context());
self.push_rewrite(ii.span, rewrite);
}
ast::ImplItemKind::Type(ref ty) => {
- let rewrite = rewrite_associated_type(ii.ident,
- Some(ty),
- None,
- &self.get_context(),
- self.block_indent);
+ let rewrite = rewrite_associated_impl_type(ii.ident,
+ ii.defaultness,
+ Some(ty),
+ None,
+ &self.get_context(),
+ self.block_indent);
self.push_rewrite(ii.span, rewrite);
}
ast::ImplItemKind::Macro(ref mac) => {
let rewrite = rewrite_macro(mac,
ident,
&self.get_context(),
- width,
- self.block_indent,
+ Shape::legacy(width, self.block_indent),
pos);
self.push_rewrite(mac.span, rewrite);
}
self.format_missing_with_indent(source!(self, first.span).lo);
let rewrite = outers.rewrite(&self.get_context(),
- self.config.max_width - self.block_indent.width(),
- self.block_indent)
+ Shape::legacy(self.config.max_width -
+ self.block_indent.width(),
+ self.block_indent))
.unwrap();
self.buffer.push_str(&rewrite);
let last = outers.last().unwrap();
parse_session: self.parse_session,
codemap: self.codemap,
config: self.config,
- block_indent: self.block_indent,
}
}
}
impl<'a> Rewrite for [ast::Attribute] {
- fn rewrite(&self, context: &RewriteContext, _: usize, offset: Indent) -> Option<String> {
+ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
let mut result = String::new();
if self.is_empty() {
return Some(result);
}
- let indent = offset.to_string(context.config);
+ let indent = shape.indent.to_string(context.config);
for (i, a) in self.iter().enumerate() {
let mut a_str = context.snippet(a.span);
if !comment.is_empty() {
let comment = try_opt!(rewrite_comment(comment,
false,
- context.config.ideal_width -
- offset.width(),
- offset,
+ Shape::legacy(context.config
+ .comment_width -
+ shape.indent.width(),
+ shape.indent),
context.config));
result.push_str(&indent);
result.push_str(&comment);
if a_str.starts_with("//") {
a_str = try_opt!(rewrite_comment(&a_str,
false,
- context.config.ideal_width - offset.width(),
- offset,
+ Shape::legacy(context.config.comment_width -
+ shape.indent.width(),
+ shape.indent),
context.config));
}