Skip to content

Commit f66f6c9

Browse files
committed
Do not assert in op_to_const.
1 parent 31bc7e2 commit f66f6c9

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ pub(super) fn op_to_const<'tcx>(
132132
// functionality.)
133133
_ => false,
134134
};
135-
let immediate = if force_as_immediate {
136-
Right(ecx.read_immediate(op).expect("normalization works on validated constants"))
135+
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) {
136+
Right(imm)
137137
} else {
138138
op.as_mplace_or_imm()
139139
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// build-pass
2+
// compile-flags:-Zmir-opt-level=4 --emit=mir
3+
4+
#![feature(allocator_api)]
5+
6+
use std::alloc::{Allocator, Global, Layout};
7+
8+
fn main() {
9+
let layout: Layout = None.unwrap();
10+
let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
11+
}

0 commit comments

Comments
 (0)