about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-03 09:43:52 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-11-25 08:10:52 +0000
commitccaa28bf694a4a8081e2a2e0e4c84842f4205ed0 (patch)
tree61a05de5dec1ecac8cb37f32c1a48b0ab6469f9d
parent2bed079103fc125294fef254575e5dc9c709dd60 (diff)
Don't try to compute the layout of generic types.
-rw-r--r--compiler/rustc_lint/src/builtin.rs46
1 files changed, 23 insertions, 23 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index 5bc130e14c5..b45ba0dcd5f 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -2504,32 +2504,32 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
             });
 
             // Check if this ADT has a constrained layout (like `NonNull` and friends).
-            let layout = cx.tcx.layout_of(cx.param_env.and(ty)).unwrap();
-
-            match &layout.abi {
-                Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => {
-                    let range = scalar.valid_range(cx);
-                    if !range.contains(0) {
-                        Some(
-                            InitError::from(format!("`{}` must be non-null", ty)).nested(field_err),
-                        )
-                    } else if init == InitKind::Uninit && !scalar.is_always_valid(cx) {
-                        // Prefer reporting on the fields over the entire struct for uninit,
-                        // as the information bubbles out and it may be unclear why the type can't
-                        // be null from just its outside signature.
-                        Some(
-                            InitError::from(format!(
-                                "`{}` must be initialized inside its custom valid range",
-                                ty,
-                            ))
-                            .nested(field_err),
-                        )
-                    } else {
-                        field_err
+            if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) {
+                match &layout.abi {
+                    Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => {
+                        let range = scalar.valid_range(cx);
+                        if !range.contains(0) {
+                            return Some(
+                                InitError::from(format!("`{}` must be non-null", ty))
+                                    .nested(field_err),
+                            );
+                        } else if init == InitKind::Uninit && !scalar.is_always_valid(cx) {
+                            // Prefer reporting on the fields over the entire struct for uninit,
+                            // as the information bubbles out and it may be unclear why the type can't
+                            // be null from just its outside signature.
+                            return Some(
+                                InitError::from(format!(
+                                    "`{}` must be initialized inside its custom valid range",
+                                    ty,
+                                ))
+                                .nested(field_err),
+                            );
+                        }
                     }
+                    _ => {}
                 }
-                _ => field_err,
             }
+            field_err
         }
 
         /// Return `Some` only if we are sure this type does *not*