@@ -4447,7 +4447,9 @@ fn init_local(bcx: @block_ctxt, local: &@ast::local) -> result {
4447
4447
// Make a note to drop this slot on the way out.
4448
4448
add_clean ( bcx, llptr, ty) ;
4449
4449
4450
- if must_zero ( local) { bcx = zero_alloca ( bcx, llptr, ty) . bcx ; }
4450
+ if must_zero ( bcx_ccx ( bcx) , local) {
4451
+ bcx = zero_alloca ( bcx, llptr, ty) . bcx ;
4452
+ }
4451
4453
4452
4454
alt local. node . init {
4453
4455
some ( init) {
@@ -4473,36 +4475,37 @@ fn init_local(bcx: @block_ctxt, local: &@ast::local) -> result {
4473
4475
bcx. fcx . lllocals , false ) ;
4474
4476
ret rslt( bcx, llptr) ;
4475
4477
4476
- fn must_zero ( local : & @ast:: local ) -> bool {
4478
+ fn must_zero ( ccx : & @ crate_ctxt , local : & @ast:: local ) -> bool {
4477
4479
alt local. node . init {
4478
- some ( init) { might_not_init ( init. expr ) }
4480
+ some ( init) { might_not_init ( ccx , init. expr ) }
4479
4481
none. { true }
4480
4482
}
4481
4483
}
4482
4484
4483
- fn might_not_init ( expr : & @ast:: expr ) -> bool {
4484
- type env = @mutable bool ;
4485
- let e = @mutable false ;
4486
- // FIXME: Probably also need to account for expressions that
4487
- // fail but since we don't unwind yet, it doesn't seem to be a
4488
- // problem
4485
+ fn might_not_init ( ccx : & @crate_ctxt , expr : & @ast:: expr ) -> bool {
4486
+ type env = { mutable mightnt : bool ,
4487
+ ccx : @crate_ctxt } ;
4488
+ let e = { mutable mightnt: false,
4489
+ ccx: ccx} ;
4490
+ fn visit_expr ( ex : & @ast:: expr , e : & env , v : & vt < env > ) {
4491
+ let might_not_init = alt ex. node {
4492
+ ast:: expr_ret ( _) { true }
4493
+ ast:: expr_break. { true }
4494
+ ast:: expr_cont. { true }
4495
+ _ {
4496
+ let ex_ty = ty:: expr_ty ( e. ccx . tcx , ex) ;
4497
+ ty:: type_is_bot ( e. ccx . tcx , ex_ty)
4498
+ }
4499
+ } ;
4500
+ if might_not_init {
4501
+ e. mightnt = true ;
4502
+ } else { visit:: visit_expr ( ex, e, v) ; }
4503
+ }
4489
4504
let visitor =
4490
- visit:: mk_vt (
4491
- @{ visit_expr:
4492
- fn ( ex: & @ast:: expr, e: & env, v: & vt<env>) {
4493
- let might_not_init =
4494
- alt ex. node {
4495
- ast:: expr_ret ( _) { true }
4496
- ast:: expr_break. { true }
4497
- ast:: expr_cont. { true }
4498
- _ { false }
4499
- } ;
4500
- if might_not_init {
4501
- * e = true ;
4502
- } else { visit:: visit_expr ( ex, e, v) ; }
4503
- } with * visit:: default_visitor ( ) } ) ;
4505
+ visit:: mk_vt ( @{ visit_expr: visit_expr
4506
+ with * visit:: default_visitor ( ) } ) ;
4504
4507
visitor. visit_expr ( expr, e, visitor) ;
4505
- ret * e ;
4508
+ ret e . mightnt ;
4506
4509
}
4507
4510
}
4508
4511
0 commit comments