Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ef59b34

Browse files
committed
Avoid control flow expressions conditions to go multi line
Extends the multi line condition to over other control flow expressions, it now covers: `if`, `if let`, `for`, `loop`, `while`, `while let` and `match`. Refs: rust-lang#3029 Signed-off-by: Otavio Salvador <[email protected]>
1 parent 8feeddf commit ef59b34

File tree

3 files changed

+171
-17
lines changed

3 files changed

+171
-17
lines changed

src/overflow.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,15 @@ impl<'a> Context<'a> {
404404
closures::rewrite_last_closure(self.context, expr, shape)
405405
}
406406
}
407-
ast::ExprKind::Match(..) => {
407+
// When overflowing the expressions which consists of a control flow
408+
// expression, avoid condition to use multi line.
409+
ast::ExprKind::If(..)
410+
| ast::ExprKind::IfLet(..)
411+
| ast::ExprKind::ForLoop(..)
412+
| ast::ExprKind::Loop(..)
413+
| ast::ExprKind::While(..)
414+
| ast::ExprKind::WhileLet(..)
415+
| ast::ExprKind::Match(..) => {
408416
let multi_line = rewrite_cond(self.context, expr, shape)
409417
.map_or(false, |cond| cond.contains('\n'));
410418

tests/source/issue-3029.rs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,86 @@
1-
fn foo() {
2-
EvaluateJSReply::NumberValue(
3-
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
4-
Ok(ConversionResult::Success(v)) => v,
5-
_ => unreachable!(),
6-
},
7-
)
1+
fn keep_if() {
2+
{
3+
{
4+
{
5+
EvaluateJSReply::NumberValue(
6+
if FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
7+
unimplemented!();
8+
},
9+
)
10+
}
11+
}
12+
}
13+
}
14+
15+
fn keep_if_let() {
16+
{
17+
{
18+
{
19+
EvaluateJSReply::NumberValue(
20+
if let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
21+
unimplemented!();
22+
},
23+
)
24+
}
25+
}
26+
}
27+
}
28+
29+
fn keep_for() {
30+
{
31+
{
32+
{
33+
EvaluateJSReply::NumberValue(
34+
for conv in FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
35+
unimplemented!();
36+
},
37+
)
38+
}
39+
}
40+
}
41+
}
42+
43+
fn keep_loop() {
44+
{
45+
{
46+
{
47+
EvaluateJSReply::NumberValue(loop {
48+
FromJSValConvertible::from_jsval(cx, rval.handle(), ());
49+
})
50+
}
51+
}
52+
}
53+
}
54+
55+
fn keep_while() {
56+
{
57+
{
58+
{
59+
EvaluateJSReply::NumberValue(
60+
while FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
61+
unimplemented!();
62+
},
63+
)
64+
}
65+
}
66+
}
67+
}
68+
69+
fn keep_while_let() {
70+
{
71+
{
72+
{
73+
EvaluateJSReply::NumberValue(
74+
while let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
75+
unimplemented!();
76+
},
77+
)
78+
}
79+
}
80+
}
881
}
982

10-
fn bar() {
83+
fn keep_match() {
1184
{
1285
{
1386
EvaluateJSReply::NumberValue(

tests/target/issue-3029.rs

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,86 @@
1-
fn foo() {
2-
EvaluateJSReply::NumberValue(
3-
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
4-
Ok(ConversionResult::Success(v)) => v,
5-
_ => unreachable!(),
6-
},
7-
)
1+
fn keep_if() {
2+
{
3+
{
4+
{
5+
EvaluateJSReply::NumberValue(
6+
if FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
7+
unimplemented!();
8+
},
9+
)
10+
}
11+
}
12+
}
13+
}
14+
15+
fn keep_if_let() {
16+
{
17+
{
18+
{
19+
EvaluateJSReply::NumberValue(
20+
if let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
21+
unimplemented!();
22+
},
23+
)
24+
}
25+
}
26+
}
27+
}
28+
29+
fn keep_for() {
30+
{
31+
{
32+
{
33+
EvaluateJSReply::NumberValue(
34+
for conv in FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
35+
unimplemented!();
36+
},
37+
)
38+
}
39+
}
40+
}
41+
}
42+
43+
fn keep_loop() {
44+
{
45+
{
46+
{
47+
EvaluateJSReply::NumberValue(loop {
48+
FromJSValConvertible::from_jsval(cx, rval.handle(), ());
49+
})
50+
}
51+
}
52+
}
53+
}
54+
55+
fn keep_while() {
56+
{
57+
{
58+
{
59+
EvaluateJSReply::NumberValue(
60+
while FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
61+
unimplemented!();
62+
},
63+
)
64+
}
65+
}
66+
}
67+
}
68+
69+
fn keep_while_let() {
70+
{
71+
{
72+
{
73+
EvaluateJSReply::NumberValue(
74+
while let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
75+
unimplemented!();
76+
},
77+
)
78+
}
79+
}
80+
}
881
}
982

10-
fn bar() {
83+
fn keep_match() {
1184
{
1285
{
1386
EvaluateJSReply::NumberValue(

0 commit comments

Comments
 (0)