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]; +}