about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-07-25 22:14:55 +0000
committerbors <bors@rust-lang.org>2022-07-25 22:14:55 +0000
commitd72e5f2e10d6b31bf2e3e26ecc389d1f53833655 (patch)
tree55ccad4705f1107183643a71bd0502fc78741df0
parent8882578a67504bf0b4618cdb6c9ea8f2f10ef5b1 (diff)
parentab6463e9d9b5c30a77879f60318b774f1e873d31 (diff)
downloadrust-d72e5f2e10d6b31bf2e3e26ecc389d1f53833655.tar.gz
rust-d72e5f2e10d6b31bf2e3e26ecc389d1f53833655.zip
Auto merge of #9241 - Jarcho:ice_9238, r=xFrednet
Fix ICE in `miri_to_const`

fixes #9238
changelog: Fix ICE when using `#![feature(generic_const_exprs)]` in various lints
-rw-r--r--clippy_utils/src/consts.rs20
-rw-r--r--clippy_utils/src/lib.rs1
-rw-r--r--tests/ui/crashes/ice-9238.rs12
3 files changed, 19 insertions, 14 deletions
diff --git a/clippy_utils/src/consts.rs b/clippy_utils/src/consts.rs
index 6d4a48b53de..351a3f4aec8 100644
--- a/clippy_utils/src/consts.rs
+++ b/clippy_utils/src/consts.rs
@@ -619,32 +619,24 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) -
         },
         mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() {
             ty::Array(sub_type, len) => match sub_type.kind() {
-                ty::Float(FloatTy::F32) => match len.to_valtree().try_to_machine_usize(tcx) {
+                ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) {
                     Some(len) => alloc
                         .inner()
                         .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap()))
                         .to_owned()
-                        .chunks(4)
-                        .map(|chunk| {
-                            Some(Constant::F32(f32::from_le_bytes(
-                                chunk.try_into().expect("this shouldn't happen"),
-                            )))
-                        })
+                        .array_chunks::<4>()
+                        .map(|&chunk| Some(Constant::F32(f32::from_le_bytes(chunk))))
                         .collect::<Option<Vec<Constant>>>()
                         .map(Constant::Vec),
                     _ => None,
                 },
-                ty::Float(FloatTy::F64) => match len.to_valtree().try_to_machine_usize(tcx) {
+                ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) {
                     Some(len) => alloc
                         .inner()
                         .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap()))
                         .to_owned()
-                        .chunks(8)
-                        .map(|chunk| {
-                            Some(Constant::F64(f64::from_le_bytes(
-                                chunk.try_into().expect("this shouldn't happen"),
-                            )))
-                        })
+                        .array_chunks::<8>()
+                        .map(|&chunk| Some(Constant::F64(f64::from_le_bytes(chunk))))
                         .collect::<Option<Vec<Constant>>>()
                         .map(Constant::Vec),
                     _ => None,
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 46c5c2eef56..ddc7a4d4e1d 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -1,3 +1,4 @@
+#![feature(array_chunks)]
 #![feature(box_patterns)]
 #![feature(control_flow_enum)]
 #![feature(let_else)]
diff --git a/tests/ui/crashes/ice-9238.rs b/tests/ui/crashes/ice-9238.rs
new file mode 100644
index 00000000000..ee6abd519f1
--- /dev/null
+++ b/tests/ui/crashes/ice-9238.rs
@@ -0,0 +1,12 @@
+#![allow(incomplete_features)]
+#![feature(generic_const_exprs)]
+#![warn(clippy::branches_sharing_code)]
+
+const fn f() -> usize {
+    2
+}
+const C: [f64; f()] = [0f64; f()];
+
+fn main() {
+    let _ = if true { C[0] } else { C[1] };
+}