Skip to content

Commit

Permalink
Only expect mono consts in CFI
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Sep 21, 2024
1 parent d3f270b commit c0d1a13
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}
_ => {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit c0d1a13

Please sign in to comment.