Skip to content

Commit 32317b5

Browse files
authored
Rollup merge of #108364 - Nilstrieb:validity-checks-refactor, r=compiler-errors
Unify validity checks into a single query Previously, there were two queries to check whether a type allows the 0x01 or zeroed bitpattern. I am planning on adding a further initness to check in #100423, truly uninit for MaybeUninit, which would make this three queries. This seems overkill for such a small feature, so this PR unifies them into one. I am not entirely happy with the naming and key type and open for improvements. r? oli-obk
2 parents eb84167 + 4036a57 commit 32317b5

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/intrinsics/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ mod simd;
2121
pub(crate) use cpuid::codegen_cpuid_call;
2222
pub(crate) use llvm::codegen_llvm_intrinsic_call;
2323

24-
use rustc_middle::ty::layout::HasParamEnv;
24+
use rustc_middle::ty;
25+
use rustc_middle::ty::layout::{HasParamEnv, InitKind};
2526
use rustc_middle::ty::print::with_no_trimmed_paths;
2627
use rustc_middle::ty::subst::SubstsRef;
2728
use rustc_span::symbol::{kw, sym, Symbol};
@@ -642,7 +643,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
642643
if intrinsic == sym::assert_zero_valid
643644
&& !fx
644645
.tcx
645-
.permits_zero_init(fx.param_env().and(ty))
646+
.check_validity_of_init((InitKind::Zero, fx.param_env().and(ty)))
646647
.expect("expected to have layout during codegen")
647648
{
648649
with_no_trimmed_paths!({
@@ -661,7 +662,10 @@ fn codegen_regular_intrinsic_call<'tcx>(
661662
if intrinsic == sym::assert_mem_uninitialized_valid
662663
&& !fx
663664
.tcx
664-
.permits_uninit_init(fx.param_env().and(ty))
665+
.check_validity_of_init((
666+
InitKind::UninitMitigated0x01Fill,
667+
fx.param_env().and(ty),
668+
))
665669
.expect("expected to have layout during codegen")
666670
{
667671
with_no_trimmed_paths!({

0 commit comments

Comments
 (0)