From b41965539ab85e782f1d5059b02c1c744237d384 Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Fri, 23 Oct 2015 21:20:43 +0200 Subject: [PATCH] Bump match inner block indent a level --- src/expr.rs | 9 ++++----- tests/source/match.rs | 20 ++++++++++++++++++++ tests/target/match.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/expr.rs b/src/expr.rs index c619376f276..00d8ea0e0e2 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -863,7 +863,7 @@ impl Rewrite for ast::Arm { // If the patterns were previously stacked, keep them stacked. let pat_span = mk_sp(pats[0].span.lo, pats[pats.len() - 1].span.hi); let pat_str = context.snippet(pat_span); - vertical = pat_str.find('\n').is_some(); + vertical = pat_str.contains('\n'); } let pats_width = if vertical { @@ -922,10 +922,9 @@ impl Rewrite for ast::Arm { } let body_budget = try_opt!(width.checked_sub(context.config.tab_spaces)); - let next_line_body = nop_block_collapse(body.rewrite(context, - body_budget, - context.block_indent - .block_indent(context.config)), + let indent = context.block_indent.block_indent(context.config); + let inner_context = &RewriteContext { block_indent: indent, ..*context }; + let next_line_body = nop_block_collapse(body.rewrite(inner_context, body_budget, indent), body_budget); let body_str = try_opt!(match_arm_heuristic(same_line_body.as_ref().map(|x| &x[..]), diff --git a/tests/source/match.rs b/tests/source/match.rs index 9ed25756d64..9277319295e 100644 --- a/tests/source/match.rs +++ b/tests/source/match.rs @@ -243,3 +243,23 @@ fn issue508() { Some(NodeTypeId::Element(_)) => false, } } + +fn issue496() {{{{ + match def { + def::DefConst(def_id) | def::DefAssociatedConst(def_id) => + match const_eval::lookup_const_by_id(cx.tcx, def_id, Some(self.pat.id)) { + Some(const_expr) => { x }}}}}}} + +fn issue494() { + { + match stmt.node { + hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => + result.push( + StmtRef::Mirror( + Box::new(Stmt { span: stmt.span, + kind: StmtKind::Expr { + scope: cx.tcx.region_maps.node_extent(id), + expr: expr.to_ref() } }))), + } + } +} diff --git a/tests/target/match.rs b/tests/target/match.rs index 2e1a1b886ec..4df098eb4d1 100644 --- a/tests/target/match.rs +++ b/tests/target/match.rs @@ -247,3 +247,35 @@ fn issue508() { Some(NodeTypeId::Element(_)) => false, } } + +fn issue496() { + { + { + { + match def { + def::DefConst(def_id) | def::DefAssociatedConst(def_id) => + match const_eval::lookup_const_by_id(cx.tcx, def_id, Some(self.pat.id)) { + Some(const_expr) => { + x + } + }, + } + } + } + } +} + +fn issue494() { + { + match stmt.node { + hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => + result.push(StmtRef::Mirror(Box::new(Stmt { + span: stmt.span, + kind: StmtKind::Expr { + scope: cx.tcx.region_maps.node_extent(id), + expr: expr.to_ref(), + }, + }))), + } + } +}