Skip to content

Commit f68dafa

Browse files
committed
rollup merge of #18452 : bkoropoff/issue-18425
2 parents f3d72dc + 88c8a54 commit f68dafa

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

src/librustc/middle/trans/tvec.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -310,26 +310,23 @@ pub fn write_content<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
310310
return expr::trans_into(bcx, &**element, Ignore);
311311
}
312312
SaveIn(lldest) => {
313-
let count = ty::eval_repeat_count(bcx.tcx(), &**count_expr);
314-
if count == 0 {
315-
return bcx;
313+
match ty::eval_repeat_count(bcx.tcx(), &**count_expr) {
314+
0 => bcx,
315+
1 => expr::trans_into(bcx, &**element, SaveIn(lldest)),
316+
count => {
317+
let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
318+
assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));
319+
320+
let bcx = iter_vec_loop(bcx, lldest, vt,
321+
C_uint(bcx.ccx(), count),
322+
|set_bcx, lleltptr, _| {
323+
elem.shallow_copy(set_bcx, lleltptr)
324+
});
325+
326+
elem.add_clean_if_rvalue(bcx, element.id);
327+
bcx
328+
}
316329
}
317-
318-
// Some cleanup would be required in the case in which panic happens
319-
// during a copy. But given that copy constructors are not overridable,
320-
// this can only happen as a result of OOM. So we just skip out on the
321-
// cleanup since things would *probably* be broken at that point anyways.
322-
323-
let elem = unpack_datum!(bcx, expr::trans(bcx, &**element));
324-
assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));
325-
326-
let bcx = iter_vec_loop(bcx, lldest, vt,
327-
C_uint(bcx.ccx(), count), |set_bcx, lleltptr, _| {
328-
elem.shallow_copy(set_bcx, lleltptr)
329-
});
330-
331-
elem.add_clean_if_rvalue(bcx, element.id);
332-
bcx
333330
}
334331
}
335332
}

src/test/run-pass/issue-18425.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that trans doesn't ICE when translating an array repeat
12+
// expression with a count of 1 and a non-Copy element type.
13+
14+
fn main() {
15+
let _ = [box 1u, ..1];
16+
}

0 commit comments

Comments
 (0)