let s = orig.trim();
// Edge case: block comments. Let's not trim their lines (for now).
- let (opener, closer, line_start) = if block_style {
- ("/* ", " */", " * ")
- } else if !config.normalize_comments {
- if orig.starts_with("/**") {
- ("/** ", " **/", " ** ")
- } else if orig.starts_with("/*!") {
- ("/*! ", " */", " * ")
- } else if orig.starts_with("/*") {
+ let (opener, closer, line_start) =
+ if block_style {
("/* ", " */", " * ")
- } else if orig.starts_with("///") {
+ } else if !config.normalize_comments {
+ if 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("/**") {
("/// ", "", "/// ")
- } else if orig.starts_with("//!") {
+ } else if orig.starts_with("//!") || orig.starts_with("/*!") {
("//! ", "", "//! ")
} else {
("// ", "", "// ")
- }
- } else if orig.starts_with("///") || orig.starts_with("/**") {
- ("/// ", "", "/// ")
- } else if orig.starts_with("//!") || orig.starts_with("/*!") {
- ("//! ", "", "//! ")
- } else {
- ("// ", "", "// ")
- };
+ };
let max_chars = width.checked_sub(closer.len() + opener.len()).unwrap_or(1);
line.starts_with("/** ") {
&line[4..]
} 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[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("*") {
&line[1..]
offset: Indent,
allow_single_line: bool)
-> Option<String> {
+ let (budget, indent) = if !allow_single_line {
+ // We are part of an if-elseif-else chain. Our constraints are tightened.
+ // 7 = "} else" .len()
+ (try_opt!(width.checked_sub(7)), offset + 7)
+ } else {
+ (width, offset)
+ };
+
// 3 = "if ", 2 = " {"
let pat_penalty = match context.config.else_if_brace_style {
ElseIfBraceStyle::AlwaysNextLine => 3,
cond,
"let ",
" =",
- try_opt!(width.checked_sub(pat_penalty)),
- offset + 3));
+ try_opt!(budget.checked_sub(pat_penalty)),
+ indent + 3));
// Try to format if-else on single line.
if expr_type == ExprType::SubExpression && allow_single_line &&
let rewrite = match else_block.node {
// If the else expression is another if-else expression, prevent it
// from being formatted on a single line.
+ // Note how we're passing the original width and offset, as the
+ // cost of "else" should not cascade.
ast::ExprKind::IfLet(ref pat, ref cond, ref if_block, ref next_else_block) => {
rewrite_if_else(context,
cond,
-1.0
};
}
+
+fn complex_if_else() {
+ if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ } else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ ha();
+ } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
+ yo();
+ } else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ ha();
+ } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxxx {
+ yo();
+ }
+}
let cx = tp1.x + any * radius * if anticlockwise { 1.0 } else { -1.0 };
}
+
+fn complex_if_else() {
+ if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ } else if let Some(x) = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ ha();
+ } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + xxxxxxxx {
+ yo();
+ } else if let Some(x) =
+ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
+ ha();
+ } else if xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
+ xxxxxxxxx {
+ yo();
+ }
+}