Skip to content

Commit b7d456d

Browse files
committed
auto merge of #16934 : nick29581/rust/dst-bug-6, r=pcwalton
Closes #16911 r?
2 parents f7ec95e + 3c610af commit b7d456d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
170170
}
171171
}
172172
None => {
173-
cx.sess().bug(format!("can't dereference const of type {}",
173+
cx.sess().bug(format!("cannot dereference const of type {}",
174174
ty_to_string(cx.tcx(), t)).as_slice())
175175
}
176176
}
@@ -225,10 +225,12 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
225225
ty::AutoDerefRef(ref adj) => {
226226
let mut ty = ety;
227227
// Save the last autoderef in case we can avoid it.
228-
for _ in range(0, adj.autoderefs-1) {
229-
let (dv, dt) = const_deref(cx, llconst, ty, false);
230-
llconst = dv;
231-
ty = dt;
228+
if adj.autoderefs > 0 {
229+
for _ in range(0, adj.autoderefs-1) {
230+
let (dv, dt) = const_deref(cx, llconst, ty, false);
231+
llconst = dv;
232+
ty = dt;
233+
}
232234
}
233235

234236
match adj.autoref {
@@ -263,6 +265,8 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
263265
// work properly.
264266
let (_, dt) = const_deref(cx, llconst, ty, false);
265267
ty = dt;
268+
} else {
269+
llconst = const_addr_of(cx, llconst, ast::MutImmutable)
266270
}
267271

268272
match ty::get(ty).sty {

src/test/run-pass/const-vecs-and-slices.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ extern crate debug;
1212

1313
static x : [int, ..4] = [1,2,3,4];
1414
static y : &'static [int] = &[1,2,3,4];
15+
static z : &'static [int, ..4] = &[1,2,3,4];
16+
static zz : &'static [int] = [1,2,3,4];
1517

1618
pub fn main() {
1719
println!("{:?}", x[1]);
1820
println!("{:?}", y[1]);
21+
println!("{:?}", z[1]);
22+
println!("{:?}", zz[1]);
1923
assert_eq!(x[1], 2);
2024
assert_eq!(x[3], 4);
2125
assert_eq!(x[3], y[3]);
26+
assert_eq!(z[1], 2);
27+
assert_eq!(z[3], 4);
28+
assert_eq!(z[3], y[3]);
29+
assert_eq!(zz[1], 2);
30+
assert_eq!(zz[3], 4);
31+
assert_eq!(zz[3], y[3]);
2232
}

0 commit comments

Comments
 (0)