Skip to content

Commit ccaa28b

Browse files
committed
Don't try to compute the layout of generic types.
1 parent 2bed079 commit ccaa28b

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,32 +2504,32 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25042504
});
25052505

25062506
// Check if this ADT has a constrained layout (like `NonNull` and friends).
2507-
let layout = cx.tcx.layout_of(cx.param_env.and(ty)).unwrap();
2508-
2509-
match &layout.abi {
2510-
Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => {
2511-
let range = scalar.valid_range(cx);
2512-
if !range.contains(0) {
2513-
Some(
2514-
InitError::from(format!("`{}` must be non-null", ty)).nested(field_err),
2515-
)
2516-
} else if init == InitKind::Uninit && !scalar.is_always_valid(cx) {
2517-
// Prefer reporting on the fields over the entire struct for uninit,
2518-
// as the information bubbles out and it may be unclear why the type can't
2519-
// be null from just its outside signature.
2520-
Some(
2521-
InitError::from(format!(
2522-
"`{}` must be initialized inside its custom valid range",
2523-
ty,
2524-
))
2525-
.nested(field_err),
2526-
)
2527-
} else {
2528-
field_err
2507+
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) {
2508+
match &layout.abi {
2509+
Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) => {
2510+
let range = scalar.valid_range(cx);
2511+
if !range.contains(0) {
2512+
return Some(
2513+
InitError::from(format!("`{}` must be non-null", ty))
2514+
.nested(field_err),
2515+
);
2516+
} else if init == InitKind::Uninit && !scalar.is_always_valid(cx) {
2517+
// Prefer reporting on the fields over the entire struct for uninit,
2518+
// as the information bubbles out and it may be unclear why the type can't
2519+
// be null from just its outside signature.
2520+
return Some(
2521+
InitError::from(format!(
2522+
"`{}` must be initialized inside its custom valid range",
2523+
ty,
2524+
))
2525+
.nested(field_err),
2526+
);
2527+
}
25292528
}
2529+
_ => {}
25302530
}
2531-
_ => field_err,
25322531
}
2532+
field_err
25332533
}
25342534

25352535
/// Return `Some` only if we are sure this type does *not*

0 commit comments

Comments
 (0)