Skip to content

Commit

Permalink
Merge pull request rust-lang#3095 from otavio/avoid-overflow-control-…
Browse files Browse the repository at this point in the history
…flow-expr

Avoid control flow expressions conditions to go multi line
  • Loading branch information
topecongiro authored Oct 14, 2018
2 parents 8dfdca9 + ef59b34 commit c4a8cdc
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 17 deletions.
10 changes: 9 additions & 1 deletion src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,15 @@ impl<'a> Context<'a> {
closures::rewrite_last_closure(self.context, expr, shape)
}
}
ast::ExprKind::Match(..) => {
// When overflowing the expressions which consists of a control flow
// expression, avoid condition to use multi line.
ast::ExprKind::If(..)
| ast::ExprKind::IfLet(..)
| ast::ExprKind::ForLoop(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::While(..)
| ast::ExprKind::WhileLet(..)
| ast::ExprKind::Match(..) => {
let multi_line = rewrite_cond(self.context, expr, shape)
.map_or(false, |cond| cond.contains('\n'));

Expand Down
89 changes: 81 additions & 8 deletions tests/source/issue-3029.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,86 @@
fn foo() {
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
fn keep_if() {
{
{
{
EvaluateJSReply::NumberValue(
if FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_if_let() {
{
{
{
EvaluateJSReply::NumberValue(
if let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_for() {
{
{
{
EvaluateJSReply::NumberValue(
for conv in FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_loop() {
{
{
{
EvaluateJSReply::NumberValue(loop {
FromJSValConvertible::from_jsval(cx, rval.handle(), ());
})
}
}
}
}

fn keep_while() {
{
{
{
EvaluateJSReply::NumberValue(
while FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_while_let() {
{
{
{
EvaluateJSReply::NumberValue(
while let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn bar() {
fn keep_match() {
{
{
EvaluateJSReply::NumberValue(
Expand Down
89 changes: 81 additions & 8 deletions tests/target/issue-3029.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,86 @@
fn foo() {
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
fn keep_if() {
{
{
{
EvaluateJSReply::NumberValue(
if FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_if_let() {
{
{
{
EvaluateJSReply::NumberValue(
if let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_for() {
{
{
{
EvaluateJSReply::NumberValue(
for conv in FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_loop() {
{
{
{
EvaluateJSReply::NumberValue(loop {
FromJSValConvertible::from_jsval(cx, rval.handle(), ());
})
}
}
}
}

fn keep_while() {
{
{
{
EvaluateJSReply::NumberValue(
while FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn keep_while_let() {
{
{
{
EvaluateJSReply::NumberValue(
while let Some(e) = FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
unimplemented!();
},
)
}
}
}
}

fn bar() {
fn keep_match() {
{
{
EvaluateJSReply::NumberValue(
Expand Down

0 comments on commit c4a8cdc

Please sign in to comment.