Skip to content

Commit cba6561

Browse files
committed
Translate MIR Repeat (arrays)
1 parent 14db074 commit cba6561

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/librustc_trans/trans/mir/rvalue.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4949
unimplemented!()
5050
}
5151

52-
mir::Rvalue::Repeat(..) => {
53-
unimplemented!()
52+
mir::Rvalue::Repeat(ref elem, ref count) => {
53+
let elem = self.trans_operand(bcx, elem);
54+
let size = self.trans_operand(bcx, count);
55+
let base = expr::get_dataptr(bcx, lldest);
56+
tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| {
57+
build::Store(b, elem.llval, vref);
58+
b
59+
})
5460
}
5561

5662
mir::Rvalue::Aggregate(_, ref operands) => {

src/test/run-pass/mir_trans_array.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 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+
#![feature(rustc_attrs)]
11+
12+
#[rustc_mir]
13+
fn into_inner() -> [u64; 1024] {
14+
let mut x = 10 + 20;
15+
[x; 1024]
16+
}
17+
18+
fn main(){
19+
let x: &[u64] = &[30; 1024];
20+
assert_eq!(&into_inner()[..], x);
21+
}

0 commit comments

Comments
 (0)