Only expect mono consts in CFI

This commit is contained in:
Michael Goulet 2024-09-20 20:10:06 -04:00
parent d3f270b542
commit c0d1a1305d
2 changed files with 6 additions and 2 deletions

View File

@ -521,6 +521,10 @@ impl<'tcx> Const<'tcx> {
self.try_to_valtree()?.try_to_scalar() self.try_to_valtree()?.try_to_scalar()
} }
pub fn try_to_bool(self) -> Option<bool> {
self.try_to_scalar()?.to_bool().ok()
}
#[inline] #[inline]
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> { pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
self.try_to_valtree()?.try_to_target_usize(tcx) self.try_to_valtree()?.try_to_target_usize(tcx)

View File

@ -145,7 +145,7 @@ fn encode_const<'tcx>(
let _ = write!(s, "{val}"); let _ = write!(s, "{val}");
} }
ty::Bool => { 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}"); let _ = write!(s, "{val}");
} }
_ => { _ => {
@ -411,7 +411,7 @@ pub fn encode_ty<'tcx>(
ty::Array(ty0, len) => { ty::Array(ty0, len) => {
// A<array-length><element-type> // 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 mut s = String::from("A");
let _ = write!(s, "{len}"); let _ = write!(s, "{len}");
s.push_str(&encode_ty(tcx, *ty0, dict, options)); s.push_str(&encode_ty(tcx, *ty0, dict, options));