diff options
| author | Eli Friedman <eli.friedman@gmail.com> | 2015-10-21 14:35:45 -0700 |
|---|---|---|
| committer | Eli Friedman <eli.friedman@gmail.com> | 2015-10-21 14:35:45 -0700 |
| commit | e720218ffb6553764b516e074fee96eb0efb79e9 (patch) | |
| tree | ede5911024109e42891364eade16c7b67baf1be4 /src | |
| parent | ca50af7f03f7be722f1406a4fbcd2fb74cd751dc (diff) | |
Improve handling of commas after match arms.
Fixes #507. Fixes #508.
Diffstat (limited to 'src')
| -rw-r--r-- | src/expr.rs | 19 |
1 files changed, 14 insertions, 5 deletions
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<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() |
