Skip to content

Commit ab6463e

Browse files
committed
Fix ICE in miri_to_const
1 parent 20e4204 commit ab6463e

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

clippy_utils/src/consts.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -619,32 +619,24 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
619619
},
620620
mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
621621
ty::Array(sub_type, len) => match sub_type.kind() {
622-
ty::Float(FloatTy::F32) => match len.to_valtree().try_to_machine_usize(tcx) {
622+
ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) {
623623
Some(len) => alloc
624624
.inner()
625625
.inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
626626
.to_owned()
627-
.chunks(4)
628-
.map(|chunk| {
629-
Some(Constant::F32(f32::from_le_bytes(
630-
chunk.try_into().expect("this shouldn't happen"),
631-
)))
632-
})
627+
.array_chunks::<4>()
628+
.map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
633629
.collect::<Option<Vec<Constant>>>()
634630
.map(Constant::Vec),
635631
_ => None,
636632
},
637-
ty::Float(FloatTy::F64) => match len.to_valtree().try_to_machine_usize(tcx) {
633+
ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) {
638634
Some(len) => alloc
639635
.inner()
640636
.inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
641637
.to_owned()
642-
.chunks(8)
643-
.map(|chunk| {
644-
Some(Constant::F64(f64::from_le_bytes(
645-
chunk.try_into().expect("this shouldn't happen"),
646-
)))
647-
})
638+
.array_chunks::<8>()
639+
.map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
648640
.collect::<Option<Vec<Constant>>>()
649641
.map(Constant::Vec),
650642
_ => None,

clippy_utils/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(array_chunks)]
12
#![feature(box_patterns)]
23
#![feature(control_flow_enum)]
34
#![feature(let_else)]

tests/ui/crashes/ice-9238.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_const_exprs)]
3+
#![warn(clippy::branches_sharing_code)]
4+
5+
const fn f() -> usize {
6+
2
7+
}
8+
const C: [f64; f()] = [0f64; f()];
9+
10+
fn main() {
11+
let _ = if true { C[0] } else { C[1] };
12+
}

0 commit comments

Comments
 (0)