From 0de72bba3634efb9d7b637b274c8f2ec1a335bf4 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 21 Jun 2016 10:08:31 +0200 Subject: [PATCH] don't warn on casting byte strs to slices --- src/librustc_const_eval/eval.rs | 1 + src/test/run-pass/const-byte-str-cast.rs | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/test/run-pass/const-byte-str-cast.rs diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 7551bc5c234ef..34dce44004823 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 0000000000000..2f265b9112b98 --- /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 or the MIT license +// , 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]; +}