Skip to content

Commit 32622ce

Browse files
committed
auto merge of #8078 : luqmana/rust/gst, r=Aatch
Fixes #5917 by not trying to treat `&[T]` as a slice since it already is one.
2 parents 5157e05 + 68b61e8 commit 32622ce

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,16 @@ pub fn const_expr(cx: @mut CrateContext, e: @ast::expr) -> ValueRef {
211211
}
212212
ty::AutoBorrowVec(ty::re_static, m) => {
213213
assert!(m != ast::m_mutbl);
214-
let size = machine::llsize_of(cx,
215-
val_ty(llconst));
216214
assert_eq!(abi::slice_elt_base, 0);
217215
assert_eq!(abi::slice_elt_len, 1);
218-
llconst = C_struct([llptr, size]);
216+
217+
match ty::get(ty).sty {
218+
ty::ty_evec(_, ty::vstore_fixed(*)) => {
219+
let size = machine::llsize_of(cx, val_ty(llconst));
220+
llconst = C_struct([llptr, size]);
221+
}
222+
_ => {}
223+
}
219224
}
220225
_ => {
221226
cx.sess.span_bug(e.span,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
struct T(&'static [int]);
12+
13+
static A: T = T(&'static [5, 4, 3]);
14+
static B: T = T(&[5, 4, 3]);
15+
static C: T = T([5, 4, 3]);
16+
17+
pub fn main() {
18+
assert_eq!(A[0], 5);
19+
assert_eq!(B[1], 4);
20+
assert_eq!(C[2], 3);
21+
}

0 commit comments

Comments
 (0)