Skip to content

Commit

Permalink
Do not assert in op_to_const.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Oct 31, 2023
1 parent 31bc7e2 commit f66f6c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ pub(super) fn op_to_const<'tcx>(
// functionality.)
_ => false,
};
let immediate = if force_as_immediate {
Right(ecx.read_immediate(op).expect("normalization works on validated constants"))
let immediate = if force_as_immediate && let Ok(imm) = ecx.read_immediate(op) {
Right(imm)
} else {
op.as_mplace_or_imm()
};
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/mir/issue-117368-print-invalid-constant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// build-pass
// compile-flags:-Zmir-opt-level=4 --emit=mir

#![feature(allocator_api)]

use std::alloc::{Allocator, Global, Layout};

fn main() {
let layout: Layout = None.unwrap();
let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
}

0 comments on commit f66f6c9

Please sign in to comment.