Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Translate MIR Repeat (arrays)
  • Loading branch information
nagisa committed Nov 5, 2015
1 parent 14db074 commit cba6561
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/librustc_trans/trans/mir/rvalue.rs
Expand Up @@ -49,8 +49,14 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
unimplemented!()
}

mir::Rvalue::Repeat(..) => {
unimplemented!()
mir::Rvalue::Repeat(ref elem, ref count) => {
let elem = self.trans_operand(bcx, elem);
let size = self.trans_operand(bcx, count);
let base = expr::get_dataptr(bcx, lldest);
tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| {
build::Store(b, elem.llval, vref);
b
})
}

mir::Rvalue::Aggregate(_, ref operands) => {
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/mir_trans_array.rs
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]

#[rustc_mir]
fn into_inner() -> [u64; 1024] {
let mut x = 10 + 20;
[x; 1024]
}

fn main(){
let x: &[u64] = &[30; 1024];
assert_eq!(&into_inner()[..], x);
}

0 comments on commit cba6561

Please sign in to comment.