Skip to content

Commit c0d1a13

Browse files
Only expect mono consts in CFI
1 parent d3f270b commit c0d1a13

File tree

2 files changed

+6
-2
lines changed
  • compiler

2 files changed

+6
-2
lines changed

compiler/rustc_middle/src/ty/consts.rs

+4
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,10 @@ impl<'tcx> Const<'tcx> {
521521
self.try_to_valtree()?.try_to_scalar()
522522
}
523523

524+
pub fn try_to_bool(self) -> Option<bool> {
525+
self.try_to_scalar()?.to_bool().ok()
526+
}
527+
524528
#[inline]
525529
pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> {
526530
self.try_to_valtree()?.try_to_target_usize(tcx)

compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn encode_const<'tcx>(
145145
let _ = write!(s, "{val}");
146146
}
147147
ty::Bool => {
148-
let val = c.try_eval_bool(tcx, ty::ParamEnv::reveal_all()).unwrap();
148+
let val = c.try_to_bool().expect("expected monomorphic const in cfi");
149149
let _ = write!(s, "{val}");
150150
}
151151
_ => {
@@ -411,7 +411,7 @@ pub fn encode_ty<'tcx>(
411411

412412
ty::Array(ty0, len) => {
413413
// A<array-length><element-type>
414-
let len = len.eval_target_usize(tcx, ty::ParamEnv::reveal_all());
414+
let len = len.try_to_target_usize(tcx).expect("expected monomorphic const in cfi");
415415
let mut s = String::from("A");
416416
let _ = write!(s, "{len}");
417417
s.push_str(&encode_ty(tcx, *ty0, dict, options));

0 commit comments

Comments
 (0)