diff --git a/src/expr.rs b/src/expr.rs index f0a877db215..c619376f276 100644 --- a/src/expr.rs +++ b/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 { @@ -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() diff --git a/tests/source/match.rs b/tests/source/match.rs index 992d0d98bf8..9ed25756d64 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -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, + } +} diff --git a/tests/target/match.rs b/tests/target/match.rs index 7202b0e0c80..2e1a1b886ec 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -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, + } +}