mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-12 23:13:15 +00:00
Merge pull request #517 from eefriedman/match-comma
Improve handling of commas after match arms.
This commit is contained in:
commit
032e6ae833
19
src/expr.rs
19
src/expr.rs
@ -779,6 +779,7 @@ fn rewrite_match(context: &RewriteContext,
|
||||
// We couldn't format the arm, just reproduce the source.
|
||||
let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm)));
|
||||
result.push_str(&snippet);
|
||||
result.push_str(arm_comma(&arm.body));
|
||||
}
|
||||
}
|
||||
// BytePos(1) = closing match brace.
|
||||
@ -809,6 +810,18 @@ fn arm_end_pos(arm: &ast::Arm) -> BytePos {
|
||||
arm.body.span.hi
|
||||
}
|
||||
|
||||
fn arm_comma(body: &ast::Expr) -> &'static str {
|
||||
if let ast::ExprBlock(ref block) = body.node {
|
||||
if let ast::DefaultBlock = block.rules {
|
||||
""
|
||||
} else {
|
||||
","
|
||||
}
|
||||
} else {
|
||||
","
|
||||
}
|
||||
}
|
||||
|
||||
// Match arms.
|
||||
impl Rewrite for ast::Arm {
|
||||
fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
|
||||
@ -881,11 +894,7 @@ impl Rewrite for ast::Arm {
|
||||
line_start += offset.width();
|
||||
}
|
||||
|
||||
let comma = if let ast::ExprBlock(_) = body.node {
|
||||
""
|
||||
} else {
|
||||
","
|
||||
};
|
||||
let comma = arm_comma(body);
|
||||
|
||||
// Let's try and get the arm body on the same line as the condition.
|
||||
// 4 = ` => `.len()
|
||||
|
@ -226,3 +226,20 @@ fn issue280() {
|
||||
fn issue383() {
|
||||
match resolution.last_private {LastImport{..} => false, _ => true};
|
||||
}
|
||||
|
||||
fn issue507() {
|
||||
match 1 {
|
||||
1 => unsafe { std::intrinsics::abort() },
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn issue508() {
|
||||
match s.type_id() {
|
||||
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLCanvasElement))) => true,
|
||||
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLObjectElement))) => s.has_object_data(),
|
||||
Some(NodeTypeId::Element(_)) => false,
|
||||
}
|
||||
}
|
||||
|
@ -230,3 +230,20 @@ fn issue383() {
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn issue507() {
|
||||
match 1 {
|
||||
1 => unsafe { std::intrinsics::abort() },
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn issue508() {
|
||||
match s.type_id() {
|
||||
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLCanvasElement))) => true,
|
||||
Some(NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||
HTMLElementTypeId::HTMLObjectElement))) => s.has_object_data(),
|
||||
Some(NodeTypeId::Element(_)) => false,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user