diff options
| author | bors <bors@rust-lang.org> | 2016-05-09 10:57:35 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-09 10:57:35 -0700 |
| commit | faca79fc332f62b339aee5bd994b00e52d9ac051 (patch) | |
| tree | d0dfa93f120c1e94a244c83fa97a209a3cbb090a | |
| parent | af0a433865321ee9fc5287eef63227baf4cba109 (diff) | |
| parent | 7461e450b93cea478ba3c9e1d1cac22ff1a410de (diff) | |
| download | rust-faca79fc332f62b339aee5bd994b00e52d9ac051.tar.gz rust-faca79fc332f62b339aee5bd994b00e52d9ac051.zip | |
Auto merge of #33457 - oli-obk:const_err/cast_u8_ptr, r=eddyb
casting `&[u8]` to `* const u8` doesn't work in const_eval fixes #33452 r? @eddyb cc @Ms2ger
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 6 | ||||
| -rw-r--r-- | src/test/run-pass/const-err.rs | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 9d2922ae640..19ded68a8e3 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -1117,6 +1117,12 @@ fn cast_const<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstVal, ty: ty::Ty) -> CastResult Float(f) => cast_const_float(tcx, f, ty), Char(c) => cast_const_int(tcx, Infer(c as u64), ty), Function(_) => Err(UnimplementedConstVal("casting fn pointers")), + ByteStr(_) => match ty.sty { + ty::TyRawPtr(_) => { + Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr")) + }, + _ => Err(CannotCast), + }, _ => Err(CannotCast), } } diff --git a/src/test/run-pass/const-err.rs b/src/test/run-pass/const-err.rs index 30641c1cb87..9f4ae1ad927 100644 --- a/src/test/run-pass/const-err.rs +++ b/src/test/run-pass/const-err.rs @@ -12,6 +12,7 @@ #![deny(const_err)] +const X: *const u8 = b"" as _; fn main() { let _ = ((-1 as i8) << 8 - 1) as f32; |
