about summary refs log tree commit diff
path: root/clippy_lints/src
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2024-12-25 19:59:18 +0100
committerblyxyas <blyxyas@gmail.com>2024-12-28 19:42:30 +0100
commitd7cc6c45c8f67f012b5111559bf321444e7c8722 (patch)
treec9c8712a9c2a88d4f45857efc96fca5e6b0cb8c8 /clippy_lints/src
parent592fd34c1b1dd5e810e3da264c99f9eda6bf1aa9 (diff)
downloadrust-d7cc6c45c8f67f012b5111559bf321444e7c8722.tar.gz
rust-d7cc6c45c8f67f012b5111559bf321444e7c8722.zip
borrow_interior_mutable_const ICE into FN
Convert the ICE reported in #12979 into a false negative.
We prefer a false negative to a ICE (because the ICE could
still affect the user even when not activating the lint).
Diffstat (limited to 'clippy_lints/src')
-rw-r--r--clippy_lints/src/non_copy_const.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs
index ebd301d5156..8409d179b0f 100644
--- a/clippy_lints/src/non_copy_const.rs
+++ b/clippy_lints/src/non_copy_const.rs
@@ -189,6 +189,8 @@ impl<'tcx> NonCopyConst<'tcx> {
     }
 
     fn is_value_unfrozen_raw_inner(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> bool {
+        // No branch that we check (yet) should continue if val isn't a ValTree::Branch
+        let ty::ValTree::Branch(val) = val else { return false };
         match *ty.kind() {
             // the fact that we have to dig into every structs to search enums
             // leads us to the point checking `UnsafeCell` directly is the only option.
@@ -197,12 +199,13 @@ impl<'tcx> NonCopyConst<'tcx> {
             // contained value.
             ty::Adt(def, ..) if def.is_union() => false,
             ty::Array(ty, _) => val
-                .unwrap_branch()
                 .iter()
                 .any(|field| Self::is_value_unfrozen_raw_inner(cx, *field, ty)),
             ty::Adt(def, args) if def.is_enum() => {
-                let (&variant_index, fields) = val.unwrap_branch().split_first().unwrap();
-                let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().to_u32());
+                let Some((&ty::ValTree::Leaf(variant_index), fields)) = val.split_first() else {
+                    return false;
+                };
+                let variant_index = VariantIdx::from_u32(variant_index.to_u32());
                 fields
                     .iter()
                     .copied()
@@ -215,12 +218,10 @@ impl<'tcx> NonCopyConst<'tcx> {
                     .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, field, ty))
             },
             ty::Adt(def, args) => val
-                .unwrap_branch()
                 .iter()
                 .zip(def.non_enum_variant().fields.iter().map(|field| field.ty(cx.tcx, args)))
                 .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, *field, ty)),
             ty::Tuple(tys) => val
-                .unwrap_branch()
                 .iter()
                 .zip(tys)
                 .any(|(field, ty)| Self::is_value_unfrozen_raw_inner(cx, *field, ty)),