From 819a13030f423849848520e9102c625d0cc1b722 Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 13 May 2017 21:07:36 +0900 Subject: [PATCH 1/2] Use precise width when rewriting else if --- src/expr.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index 0a2fab9cd27..5f2b1f0353e 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -986,12 +986,7 @@ impl<'a> Rewrite for ControlFlow<'a> { block_str); if let Some(else_block) = self.else_block { - // Since this is an else block, we should not indent for the assignment preceding - // the original if, so set shape.offset to shape.indent.alignment. - let shape = Shape { - offset: shape.indent.alignment, - ..shape - }; + let shape = Shape::indented(shape.indent, context.config); let mut last_in_chain = false; let rewrite = match else_block.node { // If the else expression is another if-else expression, prevent it From 5383b6cc17210d0c2038e05d5f03a6abe13b38ea Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Sat, 13 May 2017 21:08:10 +0900 Subject: [PATCH 2/2] Format source code --- src/comment.rs | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/comment.rs b/src/comment.rs index 9df303c86b2..17b1700accd 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -52,37 +52,35 @@ pub fn rewrite_comment(orig: &str, return light_rewrite_comment(orig, shape.indent, config); } - let (opener, closer, line_start) = - if block_style { + let (opener, closer, line_start) = if block_style { + ("/* ", " */", " * ") + } else if !config.normalize_comments { + if orig.starts_with("/**") && !orig.starts_with("/**/") { + ("/** ", " **/", " ** ") + } else if orig.starts_with("/*!") { + ("/*! ", " */", " * ") + } else if orig.starts_with("/*") { ("/* ", " */", " * ") - } else if !config.normalize_comments { - if orig.starts_with("/**") && !orig.starts_with("/**/") { - ("/** ", " **/", " ** ") - } else if orig.starts_with("/*!") { - ("/*! ", " */", " * ") - } else if orig.starts_with("/*") { - ("/* ", " */", " * ") - } else if orig.starts_with("///") { - ("/// ", "", "/// ") - } else if orig.starts_with("//!") { - ("//! ", "", "//! ") - } else { - ("// ", "", "// ") - } - } else if orig.starts_with("///") || - (orig.starts_with("/**") && !orig.starts_with("/**/")) { + } else if orig.starts_with("///") { ("/// ", "", "/// ") - } else if orig.starts_with("//!") || orig.starts_with("/*!") { + } else if orig.starts_with("//!") { ("//! ", "", "//! ") - } else if is_custom_comment(orig) { - if orig.chars().nth(3) == Some(' ') { - (&orig[0..4], "", &orig[0..4]) - } else { - (&orig[0..3], "", &orig[0..3]) - } } else { ("// ", "", "// ") - }; + } + } else if orig.starts_with("///") || (orig.starts_with("/**") && !orig.starts_with("/**/")) { + ("/// ", "", "/// ") + } else if orig.starts_with("//!") || orig.starts_with("/*!") { + ("//! ", "", "//! ") + } else if is_custom_comment(orig) { + if orig.chars().nth(3) == Some(' ') { + (&orig[0..4], "", &orig[0..4]) + } else { + (&orig[0..3], "", &orig[0..3]) + } + } else { + ("// ", "", "// ") + }; let max_chars = shape .width