diff --git a/src/chains.rs b/src/chains.rs index 36c89eef20d..4a4c123f4da 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -576,7 +576,15 @@ impl<'a> ChainFormatterShared<'a> { if all_in_one_line || extendable { // First we try to 'overflow' the last child and see if it looks better than using // vertical layout. - if let Some(one_line_shape) = last_shape.offset_left(almost_total) { + let one_line_shape = if context.use_block_indent() { + last_shape.offset_left(almost_total) + } else { + last_shape + .visual_indent(almost_total) + .sub_width(almost_total) + }; + + if let Some(one_line_shape) = one_line_shape { if let Some(rw) = last.rewrite(context, one_line_shape) { // We allow overflowing here only if both of the following conditions match: // 1. The entire chain fits in a single line except the last child. diff --git a/src/expr.rs b/src/expr.rs index bdc5e82e6a9..09257e59110 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1376,8 +1376,7 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l context.config.combine_control_expr() && context.use_block_indent() && args_len == 1 } ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => { - context.use_block_indent() - || context.config.indent_style() == IndentStyle::Visual && args_len > 1 + context.use_block_indent() || context.config.indent_style() == IndentStyle::Visual } ast::ExprKind::Array(..) | ast::ExprKind::Call(..) diff --git a/tests/target/chains-visual.rs b/tests/target/chains-visual.rs index 979816f3abb..76ef99a4b59 100644 --- a/tests/target/chains-visual.rs +++ b/tests/target/chains-visual.rs @@ -37,8 +37,8 @@ fn main() { fffffffffffffffffffffffffffffffffff(a, { SCRIPT_TASK_ROOT.with(|root| { - *root.borrow_mut() = Some(&script_task); - }); + *root.borrow_mut() = Some(&script_task); + }); }); let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = @@ -47,9 +47,9 @@ fn main() { .fold(0, |acc, x| acc + x); aaaaaaaaaaaaaaaa.map(|x| { - x += 1; - x - }) + x += 1; + x + }) .filter(some_mod::some_filter) } @@ -83,16 +83,16 @@ fn floaters() { .baz(); Foo { x: val }.baz(|| { - force(); - multiline(); - }) + force(); + multiline(); + }) .quux(); Foo { y: i_am_multi_line, z: ok }.baz(|| { - force(); - multiline(); - }) + force(); + multiline(); + }) .quux(); a + match x { @@ -137,9 +137,9 @@ fn issue1434() { for _ in 0..100 { let prototype_id = PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor).chain_err(|| { - format!("could not read prototype ID at offset {:#010x}", - current_offset) - })?; + format!("could not read prototype ID at offset {:#010x}", + current_offset) + })?; } } @@ -147,12 +147,12 @@ fn issue2264() { { something.function() .map(|| { - if let a_very_very_very_very_very_very_very_very_long_variable = - compute_this_variable() - { - println!("Hello"); - } - }) + if let a_very_very_very_very_very_very_very_very_long_variable = + compute_this_variable() + { + println!("Hello"); + } + }) .collect(); } } diff --git a/tests/target/issue-2985.rs b/tests/target/issue-2985.rs index c82714aba52..37b216ea9b1 100644 --- a/tests/target/issue-2985.rs +++ b/tests/target/issue-2985.rs @@ -4,30 +4,30 @@ fn foo() { { let extra_encoder_settings = extra_encoder_settings.iter() .filter_map(|&(name, value)| { - value.split() - .next() - .something() - .something2() - .something3() - .something4() - }); + value.split() + .next() + .something() + .something2() + .something3() + .something4() + }); let extra_encoder_settings = extra_encoder_settings.iter() .filter_map(|&(name, value)| { - value.split() - .next() - .something() - .something2() - .something3() - .something4() - }) + value.split() + .next() + .something() + .something2() + .something3() + .something4() + }) .something(); if let Some(subpod) = pod.subpods.iter().find(|s| { - !s.plaintext - .as_ref() - .map(String::as_ref) - .unwrap_or("") - .is_empty() - }) { + !s.plaintext + .as_ref() + .map(String::as_ref) + .unwrap_or("") + .is_empty() + }) { do_something(); } }