Use offset_left instead of shrink_left

This commit is contained in:
Seiichi Uchida 2017-07-19 22:50:28 +09:00
parent 05d043cc5c
commit de403f4f65
6 changed files with 16 additions and 16 deletions

View File

@ -561,7 +561,7 @@ fn choose_first_connector<'a>(
if subexpr_list.is_empty() {
""
} else if extend || subexpr_list.last().map_or(false, is_try) ||
is_extendable_parent(context, parent_str)
is_extendable_parent(context, parent_str)
{
// 1 = ";", being conservative here.
if last_line_width(parent_str) + first_line_width(first_child_str) + 1 <=

View File

@ -124,7 +124,7 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle {
CommentStyle::DoubleSlash
}
} else if (orig.starts_with("///") && orig.chars().nth(3).map_or(true, |c| c != '/')) ||
(orig.starts_with("/**") && !orig.starts_with("/**/"))
(orig.starts_with("/**") && !orig.starts_with("/**/"))
{
CommentStyle::TripleSlash
} else if orig.starts_with("//!") || orig.starts_with("/*!") {
@ -314,13 +314,13 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> &'a str {
&line[opener.trim_right().len()..]
}
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") ||
line.starts_with("///") ||
line.starts_with("** ") || line.starts_with("/*!") ||
(line.starts_with("/**") && !line.starts_with("/**/"))
line.starts_with("///") ||
line.starts_with("** ") || line.starts_with("/*!") ||
(line.starts_with("/**") && !line.starts_with("/**/"))
{
&line[3..]
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//") ||
line.starts_with("**")
line.starts_with("**")
{
&line[2..]
} else if line.starts_with('*') {
@ -795,7 +795,7 @@ fn remove_comment_header(comment: &str) -> &str {
} else if comment.starts_with("//") {
&comment[2..]
} else if (comment.starts_with("/**") && !comment.starts_with("/**/")) ||
comment.starts_with("/*!")
comment.starts_with("/*!")
{
&comment[3..comment.len() - 2]
} else {

View File

@ -375,7 +375,7 @@ where
}
// Try rewriting the rhs into the remaining space.
let rhs_shape = shape.shrink_left(last_line_width(&result) + suffix.len());
let rhs_shape = shape.offset_left(last_line_width(&result) + suffix.len());
if let Some(rhs_shape) = rhs_shape {
if let Some(rhs_result) = rhs.rewrite(context, rhs_shape) {
// FIXME this should always hold.
@ -572,7 +572,7 @@ fn rewrite_closure_fn_decl(
// 1 = |
let argument_offset = nested_shape.indent + 1;
let arg_shape = try_opt!(nested_shape.shrink_left(1)).visual_indent(0);
let arg_shape = try_opt!(nested_shape.offset_left(1)).visual_indent(0);
let ret_str = try_opt!(fn_decl.output.rewrite(context, arg_shape));
let arg_items = itemize_list(
@ -1168,7 +1168,7 @@ impl<'a> ControlFlow<'a> {
let constr_shape = if self.nested_if {
// We are part of an if-elseif-else chain. Our constraints are tightened.
// 7 = "} else " .len()
try_opt!(shape.shrink_left(7))
try_opt!(shape.offset_left(7))
} else {
shape
};
@ -1243,7 +1243,7 @@ impl<'a> ControlFlow<'a> {
let block_sep = if self.cond.is_none() && between_kwd_cond_comment.is_some() {
""
} else if context.config.control_brace_style() == ControlBraceStyle::AlwaysNextLine ||
force_newline_brace
force_newline_brace
{
alt_block_sep
} else {
@ -2573,7 +2573,7 @@ fn rewrite_struct_lit<'a>(
}
StructLitField::Base(expr) => {
// 2 = ..
expr.rewrite(context, try_opt!(v_shape.shrink_left(2)))
expr.rewrite(context, try_opt!(v_shape.offset_left(2)))
.map(|s| format!("..{}", s))
}
};

View File

@ -280,7 +280,7 @@ impl<'a> FmtVisitor<'a> {
if force_newline_brace {
newline_brace = true;
} else if self.config.fn_brace_style() != BraceStyle::AlwaysNextLine &&
!result.contains('\n')
!result.contains('\n')
{
newline_brace = false;
}

View File

@ -351,7 +351,7 @@ fn complex_if_else() {
{
ha();
} else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
xxxxxxxxx
xxxxxxxxx
{
yo();
}

View File

@ -4,8 +4,8 @@ fn foo() {
condition__uses_alignment_for_first_if__2
{
} else if condition__no_alignment_for_later_else__0 ||
condition__no_alignment_for_later_else__1 ||
condition__no_alignment_for_later_else__2
condition__no_alignment_for_later_else__1 ||
condition__no_alignment_for_later_else__2
{
};
}