let first_subexpr_is_try = subexpr_list.last().map_or(false, is_try);
let (nested_shape, extend) = if !parent_rewrite_contains_newline && is_continuable(&parent) {
let nested_shape = if first_subexpr_is_try {
- parent_shape.block_indent(context.config.tab_spaces())
+ parent_shape
+ .block_indent(context.config.tab_spaces())
+ .with_max_width(context.config)
} else {
chain_indent(context, shape.add_offset(parent_rewrite.len()))
};
} else if parent_rewrite_contains_newline {
(chain_indent(context, parent_shape), false)
} else {
- (shape.block_indent(context.config.tab_spaces()), false)
+ (
+ shape
+ .block_indent(context.config.tab_spaces())
+ .with_max_width(context.config),
+ false,
+ )
};
let other_child_shape = nested_shape.with_max_width(context.config);
}
}
- // Try overflowing the last element if we are using block indent.
+ // Try overflowing the last element if we are using block indent and it goes multi line
+ // or it fits in a single line but goes over the max width.
if !fits_single_line && context.use_block_indent() {
let (init, last) = rewrites.split_at_mut(last_non_try_index);
let almost_single_line = init.iter().all(|s| !s.contains('\n'));
// FIXME: DRY!
match (rhs, new_rhs) {
(Some(ref orig_rhs), Some(ref replacement_rhs))
- if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 ||
- (orig_rhs.rewrite(context, shape).is_none() &&
- replacement_rhs.rewrite(context, new_shape).is_some()) => {
+ if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 => {
result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
result.push_str(replacement_rhs);
}