Skip to content

Commit d855202

Browse files
committed
In unsize_unique_expr, do not convert scratch value to lvalue.
Fix the issue-20055-box-trait.rs test to actually test `Box<Trait>`. Fix #21695.
1 parent 5b66c6d commit d855202

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/librustc_trans/trans/expr.rs

-5
Original file line numberDiff line numberDiff line change
@@ -475,11 +475,6 @@ fn apply_adjustments<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
475475
let info = unsized_info(bcx, k, expr.id, unboxed_ty, |t| ty::mk_uniq(tcx, t));
476476
Store(bcx, info, get_len(bcx, scratch.val));
477477

478-
let scratch = unpack_datum!(bcx,
479-
scratch.to_expr_datum().to_lvalue_datum(bcx,
480-
"fresh_uniq_fat_ptr",
481-
expr.id));
482-
483478
DatumBlock::new(bcx, scratch.to_expr_datum())
484479
}
485480
}

src/test/run-pass/issue-20055-box-trait.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// See Issues #20055 and #21695.
12+
13+
// We are checking here that the temporaries `Box<[i8, k]>`, for `k`
14+
// in 1, 2, 3, 4, that are induced by the match expression are
15+
// properly handled, in that only *one* will be initialized by
16+
// whichever arm is run, and subsequently dropped at the end of the
17+
// statement surrounding the `match`.
18+
1119
trait Boo { }
1220

1321
impl Boo for [i8; 1] { }
@@ -16,12 +24,12 @@ impl Boo for [i8; 3] { }
1624
impl Boo for [i8; 4] { }
1725

1826
pub fn foo(box_1: fn () -> Box<[i8; 1]>,
19-
box_2: fn () -> Box<[i8; 20]>,
20-
box_3: fn () -> Box<[i8; 300]>,
21-
box_4: fn () -> Box<[i8; 4000]>,
27+
box_2: fn () -> Box<[i8; 2]>,
28+
box_3: fn () -> Box<[i8; 3]>,
29+
box_4: fn () -> Box<[i8; 4]>,
2230
) {
2331
println!("Hello World 1");
24-
let _: Box<[i8]> = match 3 {
32+
let _: Box<Boo> = match 3 {
2533
1 => box_1(),
2634
2 => box_2(),
2735
3 => box_3(),
@@ -31,10 +39,10 @@ pub fn foo(box_1: fn () -> Box<[i8; 1]>,
3139
}
3240

3341
pub fn main() {
34-
fn box_1() -> Box<[i8; 1]> { Box::new( [1i8] ) }
35-
fn box_2() -> Box<[i8; 20]> { Box::new( [1i8; 20] ) }
36-
fn box_3() -> Box<[i8; 300]> { Box::new( [1i8; 300] ) }
37-
fn box_4() -> Box<[i8; 4000]> { Box::new( [1i8; 4000] ) }
42+
fn box_1() -> Box<[i8; 1]> { Box::new( [1i8; 1] ) }
43+
fn box_2() -> Box<[i8; 2]> { Box::new( [1i8; 2] ) }
44+
fn box_3() -> Box<[i8; 3]> { Box::new( [1i8; 3] ) }
45+
fn box_4() -> Box<[i8; 4]> { Box::new( [1i8; 4] ) }
3846

3947
foo(box_1, box_2, box_3, box_4);
4048
}

src/test/run-pass/issue-20055-box-unsized-array.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Issue #2005: Check that boxed fixed-size arrays are properly
12+
// accounted for (namely, only deallocated if they were actually
13+
// created) when they appear as temporaries in unused arms of a match
14+
// expression.
15+
1116
pub fn foo(box_1: fn () -> Box<[i8; 1]>,
1217
box_2: fn () -> Box<[i8; 20]>,
1318
box_3: fn () -> Box<[i8; 300]>,

0 commit comments

Comments
 (0)