about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2016-06-21 10:08:31 +0200
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2016-06-21 10:08:31 +0200
commit0de72bba3634efb9d7b637b274c8f2ec1a335bf4 (patch)
tree0bab51d0891dd94a4fdecce04895b6c8d93be1db
parent4ba60aba387b19267cace9759d9cf14682b72871 (diff)
downloadrust-0de72bba3634efb9d7b637b274c8f2ec1a335bf4.tar.gz
rust-0de72bba3634efb9d7b637b274c8f2ec1a335bf4.zip
don't warn on casting byte strs to slices
-rw-r--r--src/librustc_const_eval/eval.rs1
-rw-r--r--src/test/run-pass/const-byte-str-cast.rs15
2 files changed, 16 insertions, 0 deletions
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs
index 7551bc5c234..34dce440048 100644
--- a/src/librustc_const_eval/eval.rs
+++ b/src/librustc_const_eval/eval.rs
@@ -1116,6 +1116,7 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstVal, ty: ty::Ty)
             ty::TyRawPtr(_) => {
                 Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr"))
             },
+            ty::TyRef(..) => Err(ErrKind::UnimplementedConstVal("casting a bytestr to slice")),
             _ => Err(CannotCast),
         },
         _ => Err(CannotCast),
diff --git a/src/test/run-pass/const-byte-str-cast.rs b/src/test/run-pass/const-byte-str-cast.rs
new file mode 100644
index 00000000000..2f265b9112b
--- /dev/null
+++ b/src/test/run-pass/const-byte-str-cast.rs
@@ -0,0 +1,15 @@
+// Copyright 2013 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.
+
+#[deny(warnings)]
+
+pub fn main() {
+    let _ = b"x" as &[u8];
+}