Skip to content

Fix double indented chained closure #2239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
.collect::<Option<Vec<_>>>()?;

// Total of all items excluding the last.
let extend_last_subexpr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();
let extend_last_subexpr = if is_small_parent {
rewrites.len() == 1 && last_line_extendable(&rewrites[0])
} else {
rewrites.is_empty() && last_line_extendable(&parent_rewrite)
};
let almost_total = if extend_last_subexpr {
last_line_width(&parent_rewrite)
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/source/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ fn main() {
.map(|x| x / 2)
.fold(0, |acc, x| acc + x);

body.fold(Body::new(), |mut body, chunk| {
body.extend(chunk);
Ok(body)
}).and_then(move |body| {
let req = Request::from_parts(parts, body);
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
});

aaaaaaaaaaaaaaaa.map(|x| {
x += 1;
x
Expand Down
8 changes: 8 additions & 0 deletions tests/target/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ fn main() {
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);

body.fold(Body::new(), |mut body, chunk| {
body.extend(chunk);
Ok(body)
}).and_then(move |body| {
let req = Request::from_parts(parts, body);
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
});

aaaaaaaaaaaaaaaa
.map(|x| {
x += 1;
Expand Down