Skip to content

Commit faca79f

Browse files
committed
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
2 parents af0a433 + 7461e45 commit faca79f

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)