From: Seiichi Uchida Date: Wed, 19 Jul 2017 13:50:28 +0000 (+0900) Subject: Use offset_left instead of shrink_left X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=de403f4f65e0c22de2ebab9b034154203a204940;p=rust.git Use offset_left instead of shrink_left --- diff --git a/src/chains.rs b/src/chains.rs index fdf0a80709b..5c98308e40c 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -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 <= diff --git a/src/comment.rs b/src/comment.rs index b3fd171b86f..35ff88d86d1 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -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 { diff --git a/src/expr.rs b/src/expr.rs index 09220e9ac80..896ecebb68e 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -375,7 +375,7 @@ pub fn rewrite_pair( } // 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 @@ fn rewrite_cond( 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 @@ fn rewrite_cond( 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 @@ enum StructLitField<'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)) } }; diff --git a/src/items.rs b/src/items.rs index aa83d9a2b0d..4e989fe64e2 100644 --- a/src/items.rs +++ b/src/items.rs @@ -280,7 +280,7 @@ pub fn rewrite_fn( 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; } diff --git a/tests/target/expr.rs b/tests/target/expr.rs index 26963540fcc..4d8ab906789 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -351,7 +351,7 @@ fn complex_if_else() { { ha(); } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + - xxxxxxxxx + xxxxxxxxx { yo(); } diff --git a/tests/target/issue-1239.rs b/tests/target/issue-1239.rs index 8db0d195ae6..6b5163cf796 100644 --- a/tests/target/issue-1239.rs +++ b/tests/target/issue-1239.rs @@ -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 { }; }