Merge pull request #3090 from otavio/issue-3029

Only combine `match` if its condition expression fits in a single line
This commit is contained in:
Seiichi Uchida 2018-10-13 10:36:31 +09:00 committed by GitHub
commit a0d1f171dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 0 deletions

View File

@ -18,6 +18,7 @@ use syntax::{ast, ptr};
use closures;
use expr::{
can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr,
rewrite_cond,
};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
use macros::MacroArg;
@ -403,6 +404,16 @@ impl<'a> Context<'a> {
closures::rewrite_last_closure(self.context, expr, shape)
}
}
ast::ExprKind::Match(..) => {
let multi_line = rewrite_cond(self.context, expr, shape)
.map_or(false, |cond| cond.contains('\n'));
if multi_line {
None
} else {
expr.rewrite(self.context, shape)
}
}
_ => expr.rewrite(self.context, shape),
}
}

View File

@ -0,0 +1,21 @@
fn foo() {
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
}
fn bar() {
{
{
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
}
}
}

View File

@ -0,0 +1,21 @@
fn foo() {
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
}
fn bar() {
{
{
EvaluateJSReply::NumberValue(
match FromJSValConvertible::from_jsval(cx, rval.handle(), ()) {
Ok(ConversionResult::Success(v)) => v,
_ => unreachable!(),
},
)
}
}
}