about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-09-03 06:26:02 +0000
committerbors <bors@rust-lang.org>2014-09-03 06:26:02 +0000
commitb7d456dfea5487c13ff0389c905693aad85f775f (patch)
treed33c558d0d3189b0085e109b49c13469ebd8ceb7
parentf7ec95efbb96f8e9bcb8b5e71b5d13803e840dc9 (diff)
parent3c610af6706a66b185807b8ec721f454e16625de (diff)
downloadrust-b7d456dfea5487c13ff0389c905693aad85f775f.tar.gz
rust-b7d456dfea5487c13ff0389c905693aad85f775f.zip
auto merge of #16934 : nick29581/rust/dst-bug-6, r=pcwalton
Closes #16911 

r?
-rw-r--r--src/librustc/middle/trans/consts.rs14
-rw-r--r--src/test/run-pass/const-vecs-and-slices.rs10
2 files changed, 19 insertions, 5 deletions
diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs
index 0b80c4f0b7a..10b6adad1e3 100644
--- a/src/librustc/middle/trans/consts.rs
+++ b/src/librustc/middle/trans/consts.rs
@@ -170,7 +170,7 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
             }
         }
         None => {
-            cx.sess().bug(format!("can't dereference const of type {}",
+            cx.sess().bug(format!("cannot dereference const of type {}",
                                   ty_to_string(cx.tcx(), t)).as_slice())
         }
     }
@@ -225,10 +225,12 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
                 ty::AutoDerefRef(ref adj) => {
                     let mut ty = ety;
                     // Save the last autoderef in case we can avoid it.
-                    for _ in range(0, adj.autoderefs-1) {
-                        let (dv, dt) = const_deref(cx, llconst, ty, false);
-                        llconst = dv;
-                        ty = dt;
+                    if adj.autoderefs > 0 {
+                        for _ in range(0, adj.autoderefs-1) {
+                            let (dv, dt) = const_deref(cx, llconst, ty, false);
+                            llconst = dv;
+                            ty = dt;
+                        }
                     }
 
                     match adj.autoref {
@@ -263,6 +265,8 @@ pub fn const_expr(cx: &CrateContext, e: &ast::Expr, is_local: bool) -> (ValueRef
                                         // work properly.
                                         let (_, dt) = const_deref(cx, llconst, ty, false);
                                         ty = dt;
+                                    } else {
+                                        llconst = const_addr_of(cx, llconst, ast::MutImmutable)
                                     }
 
                                     match ty::get(ty).sty {
diff --git a/src/test/run-pass/const-vecs-and-slices.rs b/src/test/run-pass/const-vecs-and-slices.rs
index a1cd4fe4253..43e4950a244 100644
--- a/src/test/run-pass/const-vecs-and-slices.rs
+++ b/src/test/run-pass/const-vecs-and-slices.rs
@@ -12,11 +12,21 @@ extern crate debug;
 
 static x : [int, ..4] = [1,2,3,4];
 static y : &'static [int] = &[1,2,3,4];
+static z : &'static [int, ..4] = &[1,2,3,4];
+static zz : &'static [int] = [1,2,3,4];
 
 pub fn main() {
     println!("{:?}", x[1]);
     println!("{:?}", y[1]);
+    println!("{:?}", z[1]);
+    println!("{:?}", zz[1]);
     assert_eq!(x[1], 2);
     assert_eq!(x[3], 4);
     assert_eq!(x[3], y[3]);
+    assert_eq!(z[1], 2);
+    assert_eq!(z[3], 4);
+    assert_eq!(z[3], y[3]);
+    assert_eq!(zz[1], 2);
+    assert_eq!(zz[3], 4);
+    assert_eq!(zz[3], y[3]);
 }