mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Only expect mono consts in CFI
This commit is contained in:
parent
d3f270b542
commit
c0d1a1305d
@ -521,6 +521,10 @@ impl<'tcx> Const<'tcx> {
|
||||
self.try_to_valtree()?.try_to_scalar()
|
||||
}
|
||||
|
||||
pub fn try_to_bool(self) -> Option<bool> {
|
||||
self.try_to_scalar()?.to_bool().ok()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
|
||||
self.try_to_valtree()?.try_to_target_usize(tcx)
|
||||
|
@ -145,7 +145,7 @@ fn encode_const<'tcx>(
|
||||
let _ = write!(s, "{val}");
|
||||
}
|
||||
ty::Bool => {
|
||||
let val = c.try_eval_bool(tcx, ty::ParamEnv::reveal_all()).unwrap();
|
||||
let val = c.try_to_bool().expect("expected monomorphic const in cfi");
|
||||
let _ = write!(s, "{val}");
|
||||
}
|
||||
_ => {
|
||||
@ -411,7 +411,7 @@ pub fn encode_ty<'tcx>(
|
||||
|
||||
ty::Array(ty0, len) => {
|
||||
// A<array-length><element-type>
|
||||
let len = len.eval_target_usize(tcx, ty::ParamEnv::reveal_all());
|
||||
let len = len.try_to_target_usize(tcx).expect("expected monomorphic const in cfi");
|
||||
let mut s = String::from("A");
|
||||
let _ = write!(s, "{len}");
|
||||
s.push_str(&encode_ty(tcx, *ty0, dict, options));
|
||||
|
Loading…
Reference in New Issue
Block a user