use Shape;
use rewrite::{Rewrite, RewriteContext};
-use utils::{wrap_str, first_line_width, last_line_width, mk_sp};
+use utils::{wrap_str, first_line_width, last_line_width, mk_sp, last_line_extendable};
use expr::rewrite_call;
use config::IndentStyle;
use macros::convert_try_mac;
}
fn is_extendable_parent(context: &RewriteContext, parent_str: &str) -> bool {
- context.config.chain_indent() == IndentStyle::Block &&
- parent_str.lines().last().map_or(false, |s| {
- s.trim()
- .chars()
- .all(|c| c == ')' || c == ']' || c == '}' || c == '?')
- })
+ context.config.chain_indent() == IndentStyle::Block && last_line_extendable(parent_str)
}
// True if the chain is only `?`s.
use string::{StringFormat, rewrite_string};
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr,
- colon_spaces, contains_skip, mk_sp};
+ colon_spaces, contains_skip, mk_sp, last_line_extendable};
use visitor::FmtVisitor;
use config::{Config, IndentStyle, MultilineStyle, ControlBraceStyle, Style};
use comment::{FindUncommented, rewrite_comment, contains_comment, recover_comment_removed};
};
let force_newline_brace = context.config.control_style() == Style::Rfc &&
- pat_expr_string.contains('\n');
+ pat_expr_string.contains('\n') &&
+ !last_line_extendable(&pat_expr_string);
// Try to format if-else on single line.
if self.allow_single_line && context.config.single_line_if_else_max_width() > 0 {
}
}
+#[inline]
+pub fn last_line_extendable(s: &str) -> bool {
+ s.lines().last().map_or(false, |s| {
+ s.trim()
+ .chars()
+ .all(|c| c == ')' || c == ']' || c == '}' || c == '?')
+ })
+}
+
#[inline]
fn is_skip(meta_item: &MetaItem) -> bool {
match meta_item.node {