Skip to content

Commit ae51f69

Browse files
authored
Merge pull request #2239 from topecongiro/issue-2157
Fix double indented chained closure
2 parents c4c3f5b + 0c1eb20 commit ae51f69

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

src/chains.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
150150
.collect::<Option<Vec<_>>>()?;
151151

152152
// Total of all items excluding the last.
153-
let extend_last_subexpr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();
153+
let extend_last_subexpr = if is_small_parent {
154+
rewrites.len() == 1 && last_line_extendable(&rewrites[0])
155+
} else {
156+
rewrites.is_empty() && last_line_extendable(&parent_rewrite)
157+
};
154158
let almost_total = if extend_last_subexpr {
155159
last_line_width(&parent_rewrite)
156160
} else {

tests/source/chains.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ fn main() {
5353
.map(|x| x / 2)
5454
.fold(0, |acc, x| acc + x);
5555

56+
body.fold(Body::new(), |mut body, chunk| {
57+
body.extend(chunk);
58+
Ok(body)
59+
}).and_then(move |body| {
60+
let req = Request::from_parts(parts, body);
61+
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
62+
});
63+
5664
aaaaaaaaaaaaaaaa.map(|x| {
5765
x += 1;
5866
x

tests/target/chains.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ fn main() {
5454
let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
5555
xxxxxxx.map(|x| x + 5).map(|x| x / 2).fold(0, |acc, x| acc + x);
5656

57+
body.fold(Body::new(), |mut body, chunk| {
58+
body.extend(chunk);
59+
Ok(body)
60+
}).and_then(move |body| {
61+
let req = Request::from_parts(parts, body);
62+
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
63+
});
64+
5765
aaaaaaaaaaaaaaaa
5866
.map(|x| {
5967
x += 1;

0 commit comments

Comments
 (0)