Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bdb0665

Browse files
committed
Avoid spurious visible_parent_map query invocation
1 parent bbf3900 commit bdb0665

File tree

1 file changed

+27
-41
lines changed

1 file changed

+27
-41
lines changed

src/intrinsics/mod.rs

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) use cpuid::codegen_cpuid_call;
2222
pub(crate) use llvm::codegen_llvm_intrinsic_call;
2323

2424
use rustc_middle::ty::layout::HasParamEnv;
25-
use rustc_middle::ty::print::with_no_trimmed_paths;
25+
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
2626
use rustc_middle::ty::subst::SubstsRef;
2727
use rustc_span::symbol::{kw, sym, Symbol};
2828

@@ -640,47 +640,33 @@ fn codegen_regular_intrinsic_call<'tcx>(
640640
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
641641
intrinsic_args!(fx, args => (); intrinsic);
642642

643-
let layout = fx.layout_of(substs.type_at(0));
644-
if layout.abi.is_uninhabited() {
645-
with_no_trimmed_paths!({
646-
crate::base::codegen_panic_nounwind(
647-
fx,
648-
&format!("attempted to instantiate uninhabited type `{}`", layout.ty),
649-
source_info,
650-
)
651-
});
652-
return;
653-
}
654-
655-
if intrinsic == sym::assert_zero_valid
656-
&& !fx.tcx.permits_zero_init(fx.param_env().and(layout))
657-
{
658-
with_no_trimmed_paths!({
659-
crate::base::codegen_panic_nounwind(
660-
fx,
661-
&format!(
662-
"attempted to zero-initialize type `{}`, which is invalid",
663-
layout.ty
664-
),
665-
source_info,
666-
);
667-
});
668-
return;
669-
}
670-
671-
if intrinsic == sym::assert_mem_uninitialized_valid
672-
&& !fx.tcx.permits_uninit_init(fx.param_env().and(layout))
673-
{
674-
with_no_trimmed_paths!({
675-
crate::base::codegen_panic_nounwind(
676-
fx,
677-
&format!(
678-
"attempted to leave type `{}` uninitialized, which is invalid",
679-
layout.ty
680-
),
681-
source_info,
682-
)
643+
let ty = substs.type_at(0);
644+
let layout = fx.layout_of(ty);
645+
let do_panic = match intrinsic {
646+
sym::assert_inhabited => layout.abi.is_uninhabited(),
647+
sym::assert_zero_valid => !fx.tcx.permits_zero_init(fx.param_env().and(layout)),
648+
sym::assert_mem_uninitialized_valid => {
649+
!fx.tcx.permits_uninit_init(fx.param_env().and(layout))
650+
}
651+
_ => unreachable!(),
652+
};
653+
if do_panic {
654+
let msg_str = with_no_visible_paths!({
655+
with_no_trimmed_paths!({
656+
if layout.abi.is_uninhabited() {
657+
// Use this error even for the other intrinsics as it is more precise.
658+
format!("attempted to instantiate uninhabited type `{}`", ty)
659+
} else if intrinsic == sym::assert_zero_valid {
660+
format!("attempted to zero-initialize type `{}`, which is invalid", ty)
661+
} else {
662+
format!(
663+
"attempted to leave type `{}` uninitialized, which is invalid",
664+
ty
665+
)
666+
}
667+
})
683668
});
669+
crate::base::codegen_panic_nounwind(fx, &msg_str, source_info);
684670
return;
685671
}
686672
}

0 commit comments

Comments
 (0)