Skip to content

Commit b02af10

Browse files
committed
Reduce indentation in codegen_panic_intrinsic
1 parent 2fd66d7 commit b02af10

File tree

1 file changed

+47
-49
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+47
-49
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 47 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -836,58 +836,56 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
836836
// Emit a panic or a no-op for `assert_*` intrinsics.
837837
// These are intrinsics that compile to panics so that we can get a message
838838
// which mentions the offending type, even from a const context.
839-
if let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) {
840-
let ty = instance.args.type_at(0);
841-
842-
let do_panic = !bx
843-
.tcx()
844-
.check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
845-
.expect("expect to have layout during codegen");
846-
847-
let layout = bx.layout_of(ty);
848-
849-
Some(if do_panic {
850-
let msg_str = with_no_visible_paths!({
851-
with_no_trimmed_paths!({
852-
if layout.is_uninhabited() {
853-
// Use this error even for the other intrinsics as it is more precise.
854-
format!("attempted to instantiate uninhabited type `{ty}`")
855-
} else if requirement == ValidityRequirement::Zero {
856-
format!("attempted to zero-initialize type `{ty}`, which is invalid")
857-
} else {
858-
format!(
859-
"attempted to leave type `{ty}` uninitialized, which is invalid"
860-
)
861-
}
862-
})
863-
});
864-
let msg = bx.const_str(&msg_str);
839+
let Some(requirement) = ValidityRequirement::from_intrinsic(intrinsic.name) else {
840+
return None;
841+
};
865842

866-
// Obtain the panic entry point.
867-
let (fn_abi, llfn, instance) =
868-
common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);
843+
let ty = instance.args.type_at(0);
869844

870-
// Codegen the actual panic invoke/call.
871-
helper.do_call(
872-
self,
873-
bx,
874-
fn_abi,
875-
llfn,
876-
&[msg.0, msg.1],
877-
target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
878-
unwind,
879-
&[],
880-
Some(instance),
881-
mergeable_succ,
882-
)
883-
} else {
884-
// a NOP
885-
let target = target.unwrap();
886-
helper.funclet_br(self, bx, target, mergeable_succ)
887-
})
888-
} else {
889-
None
845+
let is_valid = bx
846+
.tcx()
847+
.check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
848+
.expect("expect to have layout during codegen");
849+
850+
if is_valid {
851+
// a NOP
852+
let target = target.unwrap();
853+
return Some(helper.funclet_br(self, bx, target, mergeable_succ));
890854
}
855+
856+
let layout = bx.layout_of(ty);
857+
858+
let msg_str = with_no_visible_paths!({
859+
with_no_trimmed_paths!({
860+
if layout.is_uninhabited() {
861+
// Use this error even for the other intrinsics as it is more precise.
862+
format!("attempted to instantiate uninhabited type `{ty}`")
863+
} else if requirement == ValidityRequirement::Zero {
864+
format!("attempted to zero-initialize type `{ty}`, which is invalid")
865+
} else {
866+
format!("attempted to leave type `{ty}` uninitialized, which is invalid")
867+
}
868+
})
869+
});
870+
let msg = bx.const_str(&msg_str);
871+
872+
// Obtain the panic entry point.
873+
let (fn_abi, llfn, instance) =
874+
common::build_langcall(bx, Some(source_info.span), LangItem::PanicNounwind);
875+
876+
// Codegen the actual panic invoke/call.
877+
Some(helper.do_call(
878+
self,
879+
bx,
880+
fn_abi,
881+
llfn,
882+
&[msg.0, msg.1],
883+
target.as_ref().map(|bb| (ReturnDest::Nothing, *bb)),
884+
unwind,
885+
&[],
886+
Some(instance),
887+
mergeable_succ,
888+
))
891889
}
892890

893891
fn codegen_call_terminator(

0 commit comments

Comments
 (0)