mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 21:42:44 +00:00
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:
commit
a0d1f171dc
@ -18,6 +18,7 @@ use syntax::{ast, ptr};
|
|||||||
use closures;
|
use closures;
|
||||||
use expr::{
|
use expr::{
|
||||||
can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_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 lists::{definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator};
|
||||||
use macros::MacroArg;
|
use macros::MacroArg;
|
||||||
@ -403,6 +404,16 @@ impl<'a> Context<'a> {
|
|||||||
closures::rewrite_last_closure(self.context, expr, shape)
|
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),
|
_ => expr.rewrite(self.context, shape),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
tests/source/issue-3029.rs
Normal file
21
tests/source/issue-3029.rs
Normal 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!(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
tests/target/issue-3029.rs
Normal file
21
tests/target/issue-3029.rs
Normal 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!(),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user