Skip to content

Commit

Permalink
Auto merge of #33457 - oli-obk:const_err/cast_u8_ptr, r=eddyb
Browse files Browse the repository at this point in the history
casting `&[u8]` to `* const u8` doesn't work in const_eval

fixes #33452

r? @eddyb

cc @Ms2ger
  • Loading branch information
bors committed May 9, 2016
2 parents af0a433 + 7461e45 commit faca79f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/const-err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#![deny(const_err)]

const X: *const u8 = b"" as _;

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

0 comments on commit faca79f

Please sign in to comment.