Skip to content

Commit

Permalink
Fix ICE translating array repeat expr of non-Copy type
Browse files Browse the repository at this point in the history
The type checker permits an array repeat expression of non-Copy
type if the count is 1, but trans asserts on it prior to this
change.

Closes rust-lang#18425
  • Loading branch information
bkoropoff committed Oct 30, 2014
1 parent 15dd90b commit 8384dd9
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,26 +310,23 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
return expr::trans_into(bcx, &**element, Ignore);
}
SaveIn(lldest) => {
let count = ty::eval_repeat_count(bcx.tcx(), &**count_expr);
if count == 0 {
return bcx;
match ty::eval_repeat_count(bcx.tcx(), &**count_expr) {
0 => bcx,
1 => expr::trans_into(bcx, &**element, SaveIn(lldest)),
count => {
let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));

let bcx = iter_vec_loop(bcx, lldest, vt,
C_uint(bcx.ccx(), count),
|set_bcx, lleltptr, _| {
elem.shallow_copy(set_bcx, lleltptr)
});

elem.add_clean_if_rvalue(bcx, element.id);
bcx
}
}

// Some cleanup would be required in the case in which panic happens
// during a copy. But given that copy constructors are not overridable,
// this can only happen as a result of OOM. So we just skip out on the
// cleanup since things would *probably* be broken at that point anyways.

let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));

let bcx = iter_vec_loop(bcx, lldest, vt,
C_uint(bcx.ccx(), count), |set_bcx, lleltptr, _| {
elem.shallow_copy(set_bcx, lleltptr)
});

elem.add_clean_if_rvalue(bcx, element.id);
bcx
}
}
}
Expand Down

0 comments on commit 8384dd9

Please sign in to comment.