Add Indent::none(), remove make_indent.
This commit is contained in:
parent
d4108a3029
commit
03e1b27826
@ -21,7 +21,7 @@
|
||||
|
||||
use Indent;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use utils::{first_line_width, make_indent};
|
||||
use utils::first_line_width;
|
||||
use expr::rewrite_call;
|
||||
|
||||
use syntax::{ast, ptr};
|
||||
@ -117,7 +117,7 @@ pub fn rewrite_chain(mut expr: &ast::Expr,
|
||||
let connector = if fits_single_line {
|
||||
String::new()
|
||||
} else {
|
||||
format!("\n{}", make_indent(indent, context.config))
|
||||
format!("\n{}", indent.to_string(context.config))
|
||||
};
|
||||
|
||||
let first_connector = if extend {
|
||||
|
@ -15,7 +15,6 @@
|
||||
use Indent;
|
||||
use config::Config;
|
||||
use string::{StringFormat, rewrite_string};
|
||||
use utils::make_indent;
|
||||
|
||||
pub fn rewrite_comment(orig: &str,
|
||||
block_style: bool,
|
||||
@ -45,7 +44,7 @@ pub fn rewrite_comment(orig: &str,
|
||||
config: config,
|
||||
};
|
||||
|
||||
let indent_str = make_indent(offset, config);
|
||||
let indent_str = offset.to_string(config);
|
||||
let line_breaks = s.chars().filter(|&c| c == '\n').count();
|
||||
|
||||
let (_, mut s) = s.lines()
|
||||
@ -304,7 +303,7 @@ fn format_comments() {
|
||||
assert_eq!("/* test */", rewrite_comment(" //test", true, 100, Indent::new(0, 100),
|
||||
&config));
|
||||
assert_eq!("// comment\n// on a", rewrite_comment("// comment on a", false, 10,
|
||||
Indent::new(0, 0), &config));
|
||||
Indent::empty(), &config));
|
||||
|
||||
assert_eq!("// A multi line comment\n // between args.",
|
||||
rewrite_comment("// A multi line comment\n // between args.",
|
||||
|
48
src/expr.rs
48
src/expr.rs
@ -15,8 +15,7 @@
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic};
|
||||
use string::{StringFormat, rewrite_string};
|
||||
use utils::{span_after, make_indent, extra_offset, first_line_width, last_line_width, wrap_str,
|
||||
binary_search};
|
||||
use utils::{span_after, extra_offset, first_line_width, last_line_width, wrap_str, binary_search};
|
||||
use visitor::FmtVisitor;
|
||||
use config::{StructLitStyle, MultilineStyle};
|
||||
use comment::{FindUncommented, rewrite_comment, contains_comment};
|
||||
@ -268,7 +267,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
|
||||
if !ret_str.is_empty() {
|
||||
if prefix.contains('\n') {
|
||||
prefix.push('\n');
|
||||
prefix.push_str(&make_indent(argument_offset, context.config));
|
||||
prefix.push_str(&argument_offset.to_string(context.config));
|
||||
} else {
|
||||
prefix.push(' ');
|
||||
}
|
||||
@ -311,12 +310,12 @@ fn rewrite_closure(capture: ast::CaptureClause,
|
||||
.as_ref()
|
||||
.and_then(|body_expr| {
|
||||
if let ast::Expr_::ExprBlock(ref inner) = body_expr.node {
|
||||
Some(inner.rewrite(&context, 2, Indent::new(0, 0)))
|
||||
Some(inner.rewrite(&context, 2, Indent::empty()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| body.rewrite(&context, 2, Indent::new(0, 0)));
|
||||
.unwrap_or_else(|| body.rewrite(&context, 2, Indent::empty()));
|
||||
|
||||
Some(format!("{} {}", prefix, try_opt!(body_rewrite)))
|
||||
}
|
||||
@ -592,11 +591,11 @@ fn single_line_if_else(context: &RewriteContext,
|
||||
|
||||
let new_width = try_opt!(width.checked_sub(pat_expr_str.len() + fixed_cost));
|
||||
let if_expr = if_node.expr.as_ref().unwrap();
|
||||
let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::new(0, 0)));
|
||||
let if_str = try_opt!(if_expr.rewrite(context, new_width, Indent::empty()));
|
||||
|
||||
let new_width = try_opt!(new_width.checked_sub(if_str.len()));
|
||||
let else_expr = else_node.expr.as_ref().unwrap();
|
||||
let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::new(0, 0)));
|
||||
let else_str = try_opt!(else_expr.rewrite(context, new_width, Indent::empty()));
|
||||
|
||||
// FIXME: this check shouldn't be necessary. Rewrites should either fail
|
||||
// or wrap to a newline when the object does not fit the width.
|
||||
@ -638,7 +637,7 @@ fn rewrite_match(context: &RewriteContext,
|
||||
|
||||
let nested_context = context.nested_context();
|
||||
let arm_indent = nested_context.block_indent + context.overflow_indent;
|
||||
let arm_indent_str = make_indent(arm_indent, context.config);
|
||||
let arm_indent_str = arm_indent.to_string(context.config);
|
||||
|
||||
let open_brace_pos = span_after(mk_sp(cond.span.hi, arm_start_pos(&arms[0])),
|
||||
"{",
|
||||
@ -688,7 +687,7 @@ fn rewrite_match(context: &RewriteContext,
|
||||
// match expression, but meh.
|
||||
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(context.block_indent + context.overflow_indent, context.config));
|
||||
result.push_str(&(context.block_indent + context.overflow_indent).to_string(context.config));
|
||||
result.push('}');
|
||||
Some(result)
|
||||
}
|
||||
@ -710,7 +709,7 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos {
|
||||
impl Rewrite for ast::Arm {
|
||||
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
|
||||
let &ast::Arm { ref attrs, ref pats, ref guard, ref body } = self;
|
||||
let indent_str = make_indent(offset, context.config);
|
||||
let indent_str = offset.to_string(context.config);
|
||||
|
||||
// FIXME this is all a bit grotty, would be nice to abstract out the
|
||||
// treatment of attributes.
|
||||
@ -738,7 +737,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
|
||||
.map(|p| {
|
||||
p.rewrite(context,
|
||||
pat_budget,
|
||||
offset.block_indent(context.config.tab_spaces))
|
||||
offset.block_indent(context.config))
|
||||
})
|
||||
.collect::<Option<Vec<_>>>());
|
||||
|
||||
@ -784,7 +783,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
|
||||
|
||||
let mut line_indent = offset + pats_width;
|
||||
if vertical {
|
||||
line_indent = line_indent.block_indent(context.config.tab_spaces);
|
||||
line_indent = line_indent.block_indent(context.config);
|
||||
}
|
||||
|
||||
let comma = if let ast::ExprBlock(_) = body.node {
|
||||
@ -819,7 +818,7 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
|
||||
Some(format!("{}{} =>\n{}{},",
|
||||
attr_str.trim_left(),
|
||||
pats_str,
|
||||
make_indent(offset.block_indent(context.config.tab_spaces), context.config),
|
||||
offset.block_indent(context.config).to_string(context.config),
|
||||
body_str))
|
||||
}
|
||||
}
|
||||
@ -849,11 +848,10 @@ fn rewrite_guard(context: &RewriteContext,
|
||||
if overhead < width {
|
||||
let cond_str = guard.rewrite(context,
|
||||
width - overhead,
|
||||
offset.block_indent(context.config.tab_spaces));
|
||||
offset.block_indent(context.config));
|
||||
if let Some(cond_str) = cond_str {
|
||||
return Some(format!("\n{}if {}",
|
||||
make_indent(offset.block_indent(context.config.tab_spaces),
|
||||
context.config),
|
||||
offset.block_indent(context.config).to_string(context.config),
|
||||
cond_str));
|
||||
}
|
||||
}
|
||||
@ -908,7 +906,7 @@ fn rewrite_pat_expr(context: &RewriteContext,
|
||||
|
||||
// The expression won't fit on the current line, jump to next.
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(pat_offset, context.config));
|
||||
result.push_str(&pat_offset.to_string(context.config));
|
||||
|
||||
let expr_rewrite = expr.rewrite(context,
|
||||
context.config.max_width - pat_offset.width(),
|
||||
@ -1067,7 +1065,7 @@ enum StructLitField<'a> {
|
||||
StructLitStyle::Block => {
|
||||
// If we are all on one line, then we'll ignore the indent, and we
|
||||
// have a smaller budget.
|
||||
let indent = context.block_indent.block_indent(context.config.tab_spaces);
|
||||
let indent = context.block_indent.block_indent(context.config);
|
||||
let v_budget = context.config.max_width.checked_sub(indent.width()).unwrap_or(0);
|
||||
(indent, v_budget)
|
||||
}
|
||||
@ -1139,10 +1137,10 @@ enum StructLitField<'a> {
|
||||
let fields_str = try_opt!(write_list(&items.collect::<Vec<_>>(), &fmt));
|
||||
|
||||
let format_on_newline = || {
|
||||
let inner_indent = make_indent(context.block_indent
|
||||
.block_indent(context.config.tab_spaces),
|
||||
context.config);
|
||||
let outer_indent = make_indent(context.block_indent, context.config);
|
||||
let inner_indent = context.block_indent
|
||||
.block_indent(context.config)
|
||||
.to_string(context.config);
|
||||
let outer_indent = context.block_indent.to_string(context.config);
|
||||
Some(format!("{} {{\n{}{}\n{}}}", path_str, inner_indent, fields_str, outer_indent))
|
||||
};
|
||||
|
||||
@ -1255,7 +1253,7 @@ fn rewrite_binary_op(context: &RewriteContext,
|
||||
Some(format!("{} {}\n{}{}",
|
||||
try_opt!(lhs.rewrite(context, budget, offset)),
|
||||
operator_str,
|
||||
make_indent(offset, context.config),
|
||||
offset.to_string(context.config),
|
||||
rhs_result))
|
||||
}
|
||||
|
||||
@ -1319,8 +1317,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
|
||||
None => {
|
||||
// Expression did not fit on the same line as the identifier. Retry
|
||||
// on the next line.
|
||||
let new_offset = offset.block_indent(context.config.tab_spaces);
|
||||
result.push_str(&format!("\n{}", make_indent(new_offset, context.config)));
|
||||
let new_offset = offset.block_indent(context.config);
|
||||
result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
|
||||
|
||||
// FIXME: we probably should related max_width to width instead of config.max_width
|
||||
// where is the 1 coming from anyway?
|
||||
|
54
src/items.rs
54
src/items.rs
@ -11,8 +11,7 @@
|
||||
// Formatting top-level items - functions, structs, enums, traits, impls.
|
||||
|
||||
use Indent;
|
||||
use utils::{format_mutability, format_visibility, make_indent, contains_skip, span_after,
|
||||
end_typaram, wrap_str};
|
||||
use utils::{format_mutability, format_visibility, contains_skip, span_after, end_typaram, wrap_str};
|
||||
use lists::{write_list, itemize_list, ListItem, ListFormatting, SeparatorTactic, ListTactic};
|
||||
use expr::rewrite_assign_rhs;
|
||||
use comment::FindUncommented;
|
||||
@ -35,7 +34,7 @@ pub fn visit_let(&mut self, local: &ast::Local, span: Span) {
|
||||
|
||||
if let Some(ref ty) = local.ty {
|
||||
infix.push_str(": ");
|
||||
infix.push_str(&ty.rewrite(&self.get_context(), 1000, Indent::new(0, 0)).unwrap());
|
||||
infix.push_str(&ty.rewrite(&self.get_context(), 1000, Indent::empty()).unwrap());
|
||||
}
|
||||
|
||||
if local.init.is_some() {
|
||||
@ -126,7 +125,7 @@ pub fn rewrite_fn(&mut self,
|
||||
// this.
|
||||
if newline_brace {
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(indent, self.config));
|
||||
result.push_str(&indent.to_string(self.config));
|
||||
} else {
|
||||
result.push(' ');
|
||||
}
|
||||
@ -226,17 +225,17 @@ fn rewrite_fn_base(&mut self,
|
||||
if one_line_budget <= 0 {
|
||||
if self.config.fn_args_paren_newline {
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(arg_indent, self.config));
|
||||
result.push_str(&arg_indent.to_string(self.config));
|
||||
arg_indent = arg_indent + 1; // extra space for `(`
|
||||
result.push('(');
|
||||
} else {
|
||||
result.push_str("(\n");
|
||||
result.push_str(&make_indent(arg_indent, self.config));
|
||||
result.push_str(&arg_indent.to_string(self.config));
|
||||
}
|
||||
} else if self.config.fn_args_layout == StructLitStyle::Block {
|
||||
arg_indent = indent.block_indent(self.config.tab_spaces);
|
||||
arg_indent = indent.block_indent(self.config);
|
||||
result.push_str("(\n");
|
||||
result.push_str(&make_indent(arg_indent, self.config));
|
||||
result.push_str(&arg_indent.to_string(self.config));
|
||||
} else {
|
||||
result.push('(');
|
||||
}
|
||||
@ -281,7 +280,7 @@ fn rewrite_fn_base(&mut self,
|
||||
};
|
||||
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(indent, self.config));
|
||||
result.push_str(&indent.to_string(self.config));
|
||||
} else {
|
||||
result.push(' ');
|
||||
}
|
||||
@ -390,7 +389,7 @@ fn rewrite_args(&self,
|
||||
|
||||
let indent = match self.config.fn_arg_indent {
|
||||
BlockIndentStyle::Inherit => indent,
|
||||
BlockIndentStyle::Tabbed => indent.block_indent(self.config.tab_spaces),
|
||||
BlockIndentStyle::Tabbed => indent.block_indent(self.config),
|
||||
BlockIndentStyle::Visual => arg_indent,
|
||||
};
|
||||
|
||||
@ -444,7 +443,7 @@ fn compute_budgets_for_args(&self,
|
||||
|
||||
// Didn't work. we must force vertical layout and put args on a newline.
|
||||
if let None = budgets {
|
||||
let new_indent = indent.block_indent(self.config.tab_spaces);
|
||||
let new_indent = indent.block_indent(self.config);
|
||||
let used_space = new_indent.width() + 2; // account for `(` and `)`
|
||||
let max_space = self.config.ideal_width + self.config.leeway;
|
||||
if used_space > max_space {
|
||||
@ -480,14 +479,13 @@ pub fn visit_enum(&mut self,
|
||||
let generics_str = self.format_generics(generics,
|
||||
" {",
|
||||
self.block_indent,
|
||||
self.block_indent
|
||||
.block_indent(self.config.tab_spaces),
|
||||
self.block_indent.block_indent(self.config),
|
||||
codemap::mk_sp(span.lo, body_start))
|
||||
.unwrap();
|
||||
self.buffer.push_str(&generics_str);
|
||||
|
||||
self.last_pos = body_start;
|
||||
self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_indent(self.config);
|
||||
for (i, f) in enum_def.variants.iter().enumerate() {
|
||||
let next_span_start: BytePos = if i == enum_def.variants.len() - 1 {
|
||||
span.hi
|
||||
@ -497,7 +495,7 @@ pub fn visit_enum(&mut self,
|
||||
|
||||
self.visit_variant(f, i == enum_def.variants.len() - 1, next_span_start);
|
||||
}
|
||||
self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config);
|
||||
|
||||
self.format_missing_with_indent(span.lo + BytePos(enum_snippet.rfind('}').unwrap() as u32),
|
||||
self.config);
|
||||
@ -530,7 +528,7 @@ fn visit_variant(&mut self, field: &ast::Variant, last_field: bool, next_span_st
|
||||
arg.ty
|
||||
.rewrite(&self.get_context(),
|
||||
1000,
|
||||
Indent::new(0, 0))
|
||||
Indent::empty())
|
||||
.unwrap()
|
||||
},
|
||||
span_after(field.span, "(", self.codemap),
|
||||
@ -672,7 +670,7 @@ fn format_struct(&self,
|
||||
single_line_cost as usize + used_budget > self.config.max_width;
|
||||
|
||||
let tactic = if break_line {
|
||||
let indentation = make_indent(offset.block_indent(self.config.tab_spaces), self.config);
|
||||
let indentation = offset.block_indent(self.config).to_string(self.config);
|
||||
result.push('\n');
|
||||
result.push_str(&indentation);
|
||||
|
||||
@ -687,7 +685,7 @@ fn format_struct(&self,
|
||||
tactic: tactic,
|
||||
separator: ",",
|
||||
trailing_separator: self.config.struct_trailing_comma,
|
||||
indent: offset.block_indent(self.config.tab_spaces),
|
||||
indent: offset.block_indent(self.config),
|
||||
h_width: self.config.max_width,
|
||||
v_width: budget,
|
||||
ends_with_newline: true,
|
||||
@ -699,7 +697,7 @@ fn format_struct(&self,
|
||||
|
||||
if break_line {
|
||||
result.push('\n');
|
||||
result.push_str(&make_indent(offset, self.config));
|
||||
result.push_str(&offset.to_string(self.config));
|
||||
}
|
||||
|
||||
result.push_str(terminator);
|
||||
@ -751,7 +749,7 @@ fn format_generics(&self,
|
||||
Density::Tall,
|
||||
span.hi));
|
||||
result.push_str(&where_clause_str);
|
||||
result.push_str(&make_indent(self.block_indent, self.config));
|
||||
result.push_str(&self.block_indent.to_string(self.config));
|
||||
result.push('\n');
|
||||
result.push_str(opener.trim());
|
||||
} else {
|
||||
@ -776,9 +774,9 @@ fn format_field(&self, field: &ast::StructField) -> String {
|
||||
ast::StructFieldKind::UnnamedField(vis) => format_visibility(vis),
|
||||
};
|
||||
// FIXME silly width, indent
|
||||
let typ = field.node.ty.rewrite(&self.get_context(), 1000, Indent::new(0, 0)).unwrap();
|
||||
let typ = field.node.ty.rewrite(&self.get_context(), 1000, Indent::empty()).unwrap();
|
||||
|
||||
let indent = self.block_indent + self.config.tab_spaces;
|
||||
let indent = self.block_indent.block_indent(self.config);
|
||||
let mut attr_str = field.node
|
||||
.attrs
|
||||
.rewrite(&self.get_context(),
|
||||
@ -787,7 +785,7 @@ fn format_field(&self, field: &ast::StructField) -> String {
|
||||
.unwrap();
|
||||
if !attr_str.is_empty() {
|
||||
attr_str.push('\n');
|
||||
attr_str.push_str(&make_indent(indent, self.config));
|
||||
attr_str.push_str(&indent.to_string(self.config));
|
||||
}
|
||||
|
||||
match name {
|
||||
@ -812,7 +810,7 @@ fn rewrite_generics(&self,
|
||||
|
||||
let offset = match self.config.generics_indent {
|
||||
BlockIndentStyle::Inherit => offset,
|
||||
BlockIndentStyle::Tabbed => offset.block_indent(self.config.tab_spaces),
|
||||
BlockIndentStyle::Tabbed => offset.block_indent(self.config),
|
||||
// 1 = <
|
||||
BlockIndentStyle::Visual => generics_offset + 1,
|
||||
};
|
||||
@ -870,7 +868,7 @@ fn rewrite_where_clause(&self,
|
||||
}
|
||||
|
||||
let extra_indent = match self.config.where_indent {
|
||||
BlockIndentStyle::Inherit => Indent::new(0, 0),
|
||||
BlockIndentStyle::Inherit => Indent::empty(),
|
||||
BlockIndentStyle::Tabbed | BlockIndentStyle::Visual => Indent::new(config.tab_spaces,
|
||||
0),
|
||||
};
|
||||
@ -879,7 +877,7 @@ fn rewrite_where_clause(&self,
|
||||
|
||||
let offset = match self.config.where_pred_indent {
|
||||
BlockIndentStyle::Inherit => indent + extra_indent,
|
||||
BlockIndentStyle::Tabbed => indent + extra_indent.block_indent(config.tab_spaces),
|
||||
BlockIndentStyle::Tabbed => indent + extra_indent.block_indent(config),
|
||||
// 6 = "where ".len()
|
||||
BlockIndentStyle::Visual => indent + extra_indent + 6,
|
||||
};
|
||||
@ -915,9 +913,7 @@ fn rewrite_where_clause(&self,
|
||||
// 9 = " where ".len() + " {".len()
|
||||
if density == Density::Tall || preds_str.contains('\n') ||
|
||||
indent.width() + 9 + preds_str.len() > self.config.max_width {
|
||||
Some(format!("\n{}where {}",
|
||||
make_indent(indent + extra_indent, self.config),
|
||||
preds_str))
|
||||
Some(format!("\n{}where {}", (indent + extra_indent).to_string(self.config), preds_str))
|
||||
} else {
|
||||
Some(format!(" where {}", preds_str))
|
||||
}
|
||||
|
22
src/lib.rs
22
src/lib.rs
@ -83,7 +83,10 @@
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub struct Indent {
|
||||
// Width of the block indent, in characters. Must be a multiple of
|
||||
// Config::tab_spaces.
|
||||
block_indent: usize,
|
||||
// Alignment in characters.
|
||||
alignment: usize,
|
||||
}
|
||||
|
||||
@ -92,13 +95,17 @@ pub fn new(block_indent: usize, alignment: usize) -> Indent {
|
||||
Indent { block_indent: block_indent, alignment: alignment }
|
||||
}
|
||||
|
||||
pub fn block_indent(mut self, block_indent: usize) -> Indent {
|
||||
self.block_indent += block_indent;
|
||||
pub fn empty() -> Indent {
|
||||
Indent::new(0, 0)
|
||||
}
|
||||
|
||||
pub fn block_indent(mut self, config: &Config) -> Indent {
|
||||
self.block_indent += config.tab_spaces;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn block_unindent(mut self, block_indent: usize) -> Indent {
|
||||
self.block_indent -= block_indent;
|
||||
pub fn block_unindent(mut self, config: &Config) -> Indent {
|
||||
self.block_indent -= config.tab_spaces;
|
||||
self
|
||||
}
|
||||
|
||||
@ -139,10 +146,7 @@ impl Sub for Indent {
|
||||
type Output = Indent;
|
||||
|
||||
fn sub(self, rhs: Indent) -> Indent {
|
||||
Indent {
|
||||
block_indent: self.block_indent - rhs.block_indent,
|
||||
alignment: self.alignment - rhs.alignment,
|
||||
}
|
||||
Indent::new(self.block_indent - rhs.block_indent, self.alignment - rhs.alignment)
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +154,7 @@ impl Add<usize> for Indent {
|
||||
type Output = Indent;
|
||||
|
||||
fn add(self, rhs: usize) -> Indent {
|
||||
Indent { block_indent: self.block_indent, alignment: self.alignment + rhs }
|
||||
Indent::new(self.block_indent, self.alignment + rhs)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
use syntax::codemap::{self, CodeMap, BytePos};
|
||||
|
||||
use Indent;
|
||||
use utils::{round_up_to_power_of_two, make_indent, wrap_str};
|
||||
use utils::{round_up_to_power_of_two, wrap_str};
|
||||
use comment::{FindUncommented, rewrite_comment, find_comment_end};
|
||||
use config::Config;
|
||||
|
||||
@ -155,7 +155,7 @@ pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> Op
|
||||
let mut result = String::with_capacity(round_up_to_power_of_two(alloc_width));
|
||||
|
||||
let mut line_len = 0;
|
||||
let indent_str = &make_indent(formatting.indent, formatting.config);
|
||||
let indent_str = &formatting.indent.to_string(formatting.config);
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
let first = i == 0;
|
||||
let last = i == items.len() - 1;
|
||||
@ -221,7 +221,7 @@ pub fn write_list<'b>(items: &[ListItem], formatting: &ListFormatting<'b>) -> Op
|
||||
let formatted_comment = rewrite_comment(comment,
|
||||
true,
|
||||
formatting.v_width,
|
||||
Indent::new(0, 0),
|
||||
Indent::empty(),
|
||||
formatting.config);
|
||||
|
||||
result.push(' ');
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use config::Config;
|
||||
use utils::make_indent;
|
||||
use visitor::FmtVisitor;
|
||||
|
||||
use syntax::codemap::{self, BytePos};
|
||||
@ -29,7 +28,7 @@ pub fn format_missing_with_indent(&mut self, end: BytePos, config: &Config) {
|
||||
// No new lines in the snippet.
|
||||
this.buffer.push_str("\n");
|
||||
}
|
||||
let indent = make_indent(this.block_indent, config);
|
||||
let indent = this.block_indent.to_string(config);
|
||||
this.buffer.push_str(&indent);
|
||||
})
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ pub fn nested_context(&self) -> RewriteContext<'a> {
|
||||
RewriteContext {
|
||||
codemap: self.codemap,
|
||||
config: self.config,
|
||||
block_indent: self.block_indent.block_indent(self.config.tab_spaces),
|
||||
block_indent: self.block_indent.block_indent(self.config),
|
||||
overflow_indent: self.overflow_indent,
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
use Indent;
|
||||
use config::Config;
|
||||
use utils::{make_indent, round_up_to_power_of_two};
|
||||
use utils::round_up_to_power_of_two;
|
||||
|
||||
use MIN_STRING;
|
||||
|
||||
@ -39,7 +39,7 @@ pub fn rewrite_string<'a>(s: &str, fmt: &StringFormat<'a>) -> String {
|
||||
|
||||
let graphemes = UnicodeSegmentation::graphemes(&*stripped_str, false).collect::<Vec<&str>>();
|
||||
|
||||
let indent = make_indent(fmt.offset, fmt.config);
|
||||
let indent = fmt.offset.to_string(fmt.config);
|
||||
let indent = &indent;
|
||||
|
||||
let mut cur_start = 0;
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
use Indent;
|
||||
use comment::FindUncommented;
|
||||
use config::Config;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
|
||||
use SKIP_ANNOTATION;
|
||||
@ -37,11 +36,6 @@ pub fn span_after(original: Span, needle: &str, codemap: &CodeMap) -> BytePos {
|
||||
original.lo + BytePos(snippet.find_uncommented(needle).unwrap() as u32 + 1)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn make_indent(indent: Indent, config: &Config) -> String {
|
||||
indent.to_string(config)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn format_visibility(vis: Visibility) -> &'static str {
|
||||
match vis {
|
||||
|
@ -102,7 +102,7 @@ fn visit_block(&mut self, b: &'v ast::Block) {
|
||||
};
|
||||
|
||||
self.last_pos = self.last_pos + brace_compensation;
|
||||
self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_indent(self.config);
|
||||
self.buffer.push_str("{");
|
||||
|
||||
for stmt in &b.stmts {
|
||||
@ -117,7 +117,7 @@ fn visit_block(&mut self, b: &'v ast::Block) {
|
||||
None => {}
|
||||
}
|
||||
|
||||
self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config);
|
||||
// TODO: we should compress any newlines here to just one
|
||||
self.format_missing_with_indent(b.span.hi - brace_compensation, self.config);
|
||||
self.buffer.push_str("}");
|
||||
@ -198,9 +198,9 @@ fn visit_item(&mut self, item: &'v ast::Item) {
|
||||
}
|
||||
ast::Item_::ItemImpl(..) |
|
||||
ast::Item_::ItemTrait(..) => {
|
||||
self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_indent(self.config);
|
||||
visit::walk_item(self, item);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config);
|
||||
}
|
||||
ast::Item_::ItemExternCrate(_) => {
|
||||
self.format_missing_with_indent(item.span.lo, self.config);
|
||||
@ -330,17 +330,17 @@ fn format_mod(&mut self, m: &ast::Mod, s: Span, ident: ast::Ident) {
|
||||
|
||||
if is_internal {
|
||||
debug!("FmtVisitor::format_mod: internal mod");
|
||||
self.block_indent = self.block_indent.block_indent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_indent(self.config);
|
||||
visit::walk_mod(self, m);
|
||||
debug!("... last_pos after: {:?}", self.last_pos);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config.tab_spaces);
|
||||
self.block_indent = self.block_indent.block_unindent(self.config);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn format_separate_mod(&mut self, m: &ast::Mod, filename: &str) {
|
||||
let filemap = self.codemap.get_filemap(filename);
|
||||
self.last_pos = filemap.start_pos;
|
||||
self.block_indent = Indent::new(0, 0);
|
||||
self.block_indent = Indent::empty();
|
||||
visit::walk_mod(self, m);
|
||||
self.format_missing(filemap.end_pos);
|
||||
}
|
||||
@ -353,7 +353,7 @@ fn format_import(&mut self, vis: ast::Visibility, vp: &ast::ViewPath, span: Span
|
||||
codemap: self.codemap,
|
||||
config: self.config,
|
||||
block_indent: self.block_indent,
|
||||
overflow_indent: Indent::new(0, 0),
|
||||
overflow_indent: Indent::empty(),
|
||||
};
|
||||
// 1 = ";"
|
||||
match vp.rewrite(&context, self.config.max_width - offset.width() - 1, offset) {
|
||||
@ -385,7 +385,7 @@ pub fn get_context(&self) -> RewriteContext {
|
||||
codemap: self.codemap,
|
||||
config: self.config,
|
||||
block_indent: self.block_indent,
|
||||
overflow_indent: Indent::new(0, 0),
|
||||
overflow_indent: Indent::empty(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -396,7 +396,7 @@ fn rewrite(&self, context: &RewriteContext, _: usize, offset: Indent) -> Option<
|
||||
if self.is_empty() {
|
||||
return Some(result);
|
||||
}
|
||||
let indent = utils::make_indent(offset, context.config);
|
||||
let indent = offset.to_string(context.config);
|
||||
|
||||
for (i, a) in self.iter().enumerate() {
|
||||
let a_str = context.snippet(a.span);
|
||||
|
Loading…
Reference in New Issue
Block a user