Skip to content

Commit db89a75

Browse files
committed
use Constant for repetition count in mir::Repeat
1 parent cba6561 commit db89a75

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/librustc_mir/build/expr/as_rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl<'a,'tcx> Builder<'a,'tcx> {
4444
}
4545
ExprKind::Repeat { value, count } => {
4646
let value_operand = unpack!(block = this.as_operand(block, value));
47-
let count_operand = unpack!(block = this.as_operand(block, count));
48-
block.and(Rvalue::Repeat(value_operand, count_operand))
47+
let count = this.as_constant(count);
48+
block.and(Rvalue::Repeat(value_operand, count))
4949
}
5050
ExprKind::Borrow { region, borrow_kind, arg } => {
5151
let arg_lvalue = unpack!(block = this.as_lvalue(block, arg));

src/librustc_mir/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ pub enum Rvalue<'tcx> {
546546
Use(Operand<'tcx>),
547547

548548
// [x; 32]
549-
Repeat(Operand<'tcx>, Operand<'tcx>),
549+
Repeat(Operand<'tcx>, Constant<'tcx>),
550550

551551
// &x or &mut x
552552
Ref(Region, BorrowKind, Lvalue<'tcx>),

src/librustc_mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub trait Visitor<'tcx> {
134134

135135
Rvalue::Repeat(ref value, ref len) => {
136136
self.visit_operand(value);
137-
self.visit_operand(len);
137+
self.visit_constant(len);
138138
}
139139

140140
Rvalue::Ref(r, bk, ref path) => {

src/librustc_trans/trans/mir/rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
5151

5252
mir::Rvalue::Repeat(ref elem, ref count) => {
5353
let elem = self.trans_operand(bcx, elem);
54-
let size = self.trans_operand(bcx, count);
54+
let size = self.trans_constant(bcx, count);
5555
let base = expr::get_dataptr(bcx, lldest);
56-
tvec::iter_vec_raw(bcx, base, elem.ty, size.llval, |b, vref, _| {
56+
tvec::iter_vec_raw(bcx, base, elem.ty, size, |b, vref, _| {
5757
build::Store(b, elem.llval, vref);
5858
b
5959
})
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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(x: u64) -> [u64; 1024] {
14+
[x; 2*4*8*16]
15+
}
16+
17+
fn main(){
18+
let x: &[u64] = &[42; 1024];
19+
assert_eq!(&into_inner(42)[..], x);
20+
}

0 commit comments

Comments
 (0)