Overflow Visual functions even with one argument

This commit is contained in:
Ivan Molodetskikh 2018-10-06 16:32:38 +03:00
parent 6dc9b96651
commit dee68434e6
No known key found for this signature in database
GPG Key ID: 02CE38DA47E9D691
4 changed files with 50 additions and 43 deletions

View File

@ -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.

View File

@ -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(..)

View File

@ -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();
}
}

View File

@ -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();
}
}