Get rid of choose_first_connector()
@@ -239,16 +239,15 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
connector.as_str()
};
- let subexpr_num = subexpr_list.len();
let result = if is_small_parent && rewrites.len() > 1 {
- let second_connector = choose_first_connector(
- context,
- &rewrites[0],
- &rewrites[1],
- &connector,
- &subexpr_list[..subexpr_num - 1],
- false,
- );
+ let second_connector = if fits_single_line || rewrites[1] == "?"
+ || last_line_extendable(&rewrites[0])
+ || context.config.chain_indent() == IndentStyle::Visual
+ {
+ ""
+ } else {
+ &connector
+ };
format!(
"{}{}{}{}{}",
parent_rewrite,
@@ -273,10 +272,6 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
}
}
-fn is_extendable_parent(context: &RewriteContext, parent_str: &str) -> bool {
- context.config.chain_indent() == IndentStyle::Block && last_line_extendable(parent_str)
-}
-
// True if the chain is only `?`s.
fn chain_only_try(exprs: &[ast::Expr]) -> bool {
exprs.iter().all(|e| if let ast::ExprKind::Try(_) = e.node {
@@ -445,32 +440,6 @@ fn is_try(expr: &ast::Expr) -> bool {
}
}
-fn choose_first_connector<'a>(
- context: &RewriteContext,
- parent_str: &str,
- first_child_str: &str,
- connector: &'a str,
- subexpr_list: &[ast::Expr],
- extend: bool,
-) -> &'a str {
- if subexpr_list.is_empty() {
- ""
- } else if extend || subexpr_list.last().map_or(false, is_try)
- || is_extendable_parent(context, parent_str)
- {
- // 1 = ";", being conservative here.
- if last_line_width(parent_str) + first_line_width(first_child_str) + 1
- <= context.config.max_width()
- {
- ""
- } else {
- connector
- }
- } else {
- connector
- }
-}
-
fn rewrite_method_call(
method_name: ast::Ident,
types: &[ptr::P<ast::Ty>],
