Skip to content

Commit bd5f908

Browse files
committed
cmse: simplify input/output check control flow
1 parent 760ea07 commit bd5f908

File tree

1 file changed

+19
-34
lines changed
  • compiler/rustc_hir_analysis/src/hir_ty_lowering

1 file changed

+19
-34
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ pub(crate) fn validate_cmse_abi<'tcx>(
1818
abi: ExternAbi,
1919
fn_sig: ty::PolyFnSig<'tcx>,
2020
) {
21-
match abi {
22-
ExternAbi::CmseNonSecureCall => {
23-
let hir_node = tcx.hir_node(hir_id);
24-
let hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), .. }) = hir_node
25-
else {
21+
let fn_decl = match abi {
22+
ExternAbi::CmseNonSecureCall => match tcx.hir_node(hir_id) {
23+
hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), .. }) => fn_ptr_ty.decl,
24+
_ => {
2625
let span = match tcx.parent_hir_node(hir_id) {
2726
hir::Node::Item(hir::Item {
2827
kind: hir::ItemKind::ForeignMod { .. },
@@ -39,26 +38,10 @@ pub(crate) fn validate_cmse_abi<'tcx>(
3938
)
4039
.emit();
4140
return;
42-
};
43-
44-
if let Err((span, layout_err)) =
45-
is_valid_cmse_inputs(tcx, dcx, fn_sig, fn_ptr_ty.decl, abi)
46-
{
47-
if should_emit_layout_error(abi, layout_err) {
48-
dcx.emit_err(errors::CmseGeneric { span, abi });
49-
}
50-
}
51-
52-
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, fn_ptr_ty.decl, abi) {
53-
if should_emit_layout_error(abi, layout_err) {
54-
let span = fn_ptr_ty.decl.output.span();
55-
dcx.emit_err(errors::CmseGeneric { span, abi });
56-
}
5741
}
58-
}
42+
},
5943
ExternAbi::CmseNonSecureEntry => {
60-
let hir_node = tcx.hir_node(hir_id);
61-
let Some(hir::FnSig { decl, .. }) = hir_node.fn_sig() else {
44+
let Some(hir::FnSig { decl, .. }) = tcx.hir_node(hir_id).fn_sig() else {
6245
// might happen when this ABI is used incorrectly. That will be handled elsewhere
6346
return;
6447
};
@@ -69,19 +52,21 @@ pub(crate) fn validate_cmse_abi<'tcx>(
6952
return;
7053
}
7154

72-
if let Err((span, layout_err)) = is_valid_cmse_inputs(tcx, dcx, fn_sig, decl, abi) {
73-
if should_emit_layout_error(abi, layout_err) {
74-
dcx.emit_err(errors::CmseGeneric { span, abi });
75-
}
76-
}
55+
decl
56+
}
57+
_ => return,
58+
};
7759

78-
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, decl, abi) {
79-
if should_emit_layout_error(abi, layout_err) {
80-
dcx.emit_err(errors::CmseGeneric { span: decl.output.span(), abi });
81-
}
82-
}
60+
if let Err((span, layout_err)) = is_valid_cmse_inputs(tcx, dcx, fn_sig, fn_decl, abi) {
61+
if should_emit_layout_error(abi, layout_err) {
62+
dcx.emit_err(errors::CmseGeneric { span, abi });
63+
}
64+
}
65+
66+
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, fn_decl, abi) {
67+
if should_emit_layout_error(abi, layout_err) {
68+
dcx.emit_err(errors::CmseGeneric { span: fn_decl.output.span(), abi });
8369
}
84-
_ => (),
8570
}
8671
}
8772

0 commit comments

Comments
 (0)