Skip to content

Commit dc18659

Browse files
committed
auto merge of #12669 : huonw/rust/de-block-arms, r=alexcrichton
syntax: make match arms store the expr directly. Previously `ast::Arm` was always storing a single `ast::Expr` wrapped in an `ast::Block` (for historical reasons, AIUI), so we might as just store that expr directly. Closes #3085.
2 parents 062e950 + c3b9047 commit dc18659

File tree

15 files changed

+30
-57
lines changed

15 files changed

+30
-57
lines changed

src/librustc/middle/cfg/construct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl CFGBuilder {
300300
guard_exit = self.opt_expr(arm.guard, guard_exit); // 2
301301
let pats_exit = self.pats_any(arm.pats.as_slice(),
302302
guard_exit); // 3
303-
let body_exit = self.block(arm.body, pats_exit); // 4
303+
let body_exit = self.expr(arm.body, pats_exit); // 4
304304
self.add_contained_edge(body_exit, expr_exit); // 5
305305
}
306306
expr_exit

src/librustc/middle/dataflow.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
534534
self.walk_pat_alternatives(arm.pats.as_slice(),
535535
body,
536536
loop_scopes);
537-
self.walk_block(arm.body, body, loop_scopes);
537+
self.walk_expr(arm.body, body, loop_scopes);
538538
join_bits(&self.dfcx.oper, body, in_out);
539539
}
540540
}
@@ -915,4 +915,3 @@ fn bit_str(bit: uint) -> ~str {
915915
let lobits = 1 << (bit & 0xFF);
916916
format!("[{}:{}-{:02x}]", bit, byte, lobits)
917917
}
918-

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ impl Liveness {
11251125
let mut first_merge = true;
11261126
for arm in arms.iter() {
11271127
let body_succ =
1128-
self.propagate_through_block(arm.body, succ);
1128+
self.propagate_through_expr(arm.body, succ);
11291129
let guard_succ =
11301130
self.propagate_through_opt_expr(arm.guard, body_succ);
11311131
let arm_succ =

src/librustc/middle/moves.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ impl VisitContext {
632632
self.consume_expr(*guard);
633633
}
634634

635-
self.consume_block(arm.body);
635+
self.consume_expr(arm.body);
636636
}
637637

638638
pub fn use_pat(&mut self, pat: @Pat) {

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4248,7 +4248,7 @@ impl Resolver {
42484248
self.check_consistent_bindings(arm);
42494249

42504250
visit::walk_expr_opt(self, arm.guard, ());
4251-
self.resolve_block(arm.body);
4251+
self.resolve_expr(arm.body);
42524252

42534253
let mut value_ribs = self.value_ribs.borrow_mut();
42544254
value_ribs.get().pop();

src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
19391939
let cleanup_scope = fcx.push_custom_cleanup_scope();
19401940
bcx = insert_lllocals(bcx, arm_data.bindings_map,
19411941
cleanup::CustomScope(cleanup_scope));
1942-
bcx = controlflow::trans_block(bcx, arm_data.arm.body, dest);
1942+
bcx = expr::trans_into(bcx, arm_data.arm.body, dest);
19431943
bcx = fcx.pop_and_trans_custom_cleanup_scope(bcx, cleanup_scope);
19441944
arm_cxs.push(bcx);
19451945
}

src/librustc/middle/trans/debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ fn populate_scope_map(cx: &CrateContext,
26652665
walk_expr(cx, *guard_exp, scope_stack, scope_map)
26662666
}
26672667

2668-
walk_block(cx, arm_ref.body, scope_stack, scope_map);
2668+
walk_expr(cx, arm_ref.body, scope_stack, scope_map);
26692669
})
26702670
}
26712671
}

src/librustc/middle/typeck/check/_match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use middle::pat_util::{PatIdMap, pat_id_map, pat_is_binding, pat_is_const};
1414
use middle::ty;
1515
use middle::typeck::check::demand;
16-
use middle::typeck::check::{check_block, check_expr_has_type, FnCtxt};
16+
use middle::typeck::check::{check_expr, check_expr_has_type, FnCtxt};
1717
use middle::typeck::check::{instantiate_path, lookup_def};
1818
use middle::typeck::check::{structure_of, valid_range_bounds};
1919
use middle::typeck::infer;
@@ -74,7 +74,7 @@ pub fn check_match(fcx: @FnCtxt,
7474
},
7575
None => ()
7676
}
77-
check_block(fcx, arm.body);
77+
check_expr(fcx, arm.body);
7878
let bty = fcx.node_ty(arm.body.id);
7979
saw_err = saw_err || ty::type_is_error(bty);
8080
if guard_err {

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub enum Decl_ {
491491
pub struct Arm {
492492
pats: Vec<@Pat> ,
493493
guard: Option<@Expr>,
494-
body: P<Block>,
494+
body: @Expr,
495495
}
496496

497497
#[deriving(Clone, Eq, Encodable, Decodable, Hash)]

src/libsyntax/ext/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
679679
ast::Arm {
680680
pats: pats,
681681
guard: None,
682-
body: self.block_expr(expr)
682+
body: expr
683683
}
684684
}
685685

0 commit comments

Comments
 (0)