Skip to content

Commit 7461e45

Browse files
committed
casting b"text" to * const u8 doesn't work in const_eval
1 parent 68d399d commit 7461e45

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustc_const_eval/eval.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,12 @@ fn cast_const<'tcx>(tcx: &TyCtxt<'tcx>, val: ConstVal, ty: ty::Ty) -> CastResult
11171117
Float(f) => cast_const_float(tcx, f, ty),
11181118
Char(c) => cast_const_int(tcx, Infer(c as u64), ty),
11191119
Function(_) => Err(UnimplementedConstVal("casting fn pointers")),
1120+
ByteStr(_) => match ty.sty {
1121+
ty::TyRawPtr(_) => {
1122+
Err(ErrKind::UnimplementedConstVal("casting a bytestr to a raw ptr"))
1123+
},
1124+
_ => Err(CannotCast),
1125+
},
11201126
_ => Err(CannotCast),
11211127
}
11221128
}

src/test/run-pass/const-err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#![deny(const_err)]
1414

15+
const X: *const u8 = b"" as _;
1516

1617
fn main() {
1718
let _ = ((-1 as i8) << 8 - 1) as f32;

0 commit comments

Comments
 (0)