cmse: rephrase error message when signature uses generics

This commit is contained in:
Folkert de Vries
2025-10-08 14:05:47 +02:00
parent b47de64cdb
commit 98d3864310
6 changed files with 49 additions and 55 deletions

View File

@@ -72,11 +72,11 @@ hir_analysis_cannot_capture_late_bound_ty =
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
.label = `for<...>` is here
hir_analysis_cmse_call_generic =
function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
hir_analysis_cmse_generic =
generics are not allowed in `extern {$abi}` signatures
hir_analysis_cmse_entry_generic =
functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
hir_analysis_cmse_impl_trait =
`impl Trait` is not allowed in `extern {$abi}` signatures
hir_analysis_cmse_inputs_stack_spill =
arguments for `{$abi}` function too large to pass via registers

View File

@@ -1632,10 +1632,19 @@ pub(crate) struct CmseOutputStackSpill {
}
#[derive(Diagnostic)]
#[diag(hir_analysis_cmse_call_generic, code = E0798)]
pub(crate) struct CmseCallGeneric {
#[diag(hir_analysis_cmse_generic, code = E0798)]
pub(crate) struct CmseGeneric {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_cmse_impl_trait, code = E0798)]
pub(crate) struct CmseImplTrait {
#[primary_span]
pub span: Span,
pub abi: ExternAbi,
}
#[derive(Diagnostic)]
@@ -1645,13 +1654,6 @@ pub(crate) struct BadReturnTypeNotation {
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_cmse_entry_generic, code = E0798)]
pub(crate) struct CmseEntryGeneric {
#[primary_span]
pub span: Span,
}
#[derive(LintDiagnostic)]
#[diag(hir_analysis_supertrait_item_shadowing)]
pub(crate) struct SupertraitItemShadowing {

View File

@@ -48,14 +48,14 @@ pub(crate) fn validate_cmse_abi<'tcx>(
Ok(()) => {}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
dcx.emit_err(errors::CmseGeneric { span: *fn_ptr_span, abi });
}
}
}
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, fn_ptr_ty.decl, abi) {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
dcx.emit_err(errors::CmseGeneric { span: *fn_ptr_span, abi });
}
}
}
@@ -76,14 +76,14 @@ pub(crate) fn validate_cmse_abi<'tcx>(
Ok(()) => {}
Err(layout_err) => {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
dcx.emit_err(errors::CmseGeneric { span: *fn_sig_span, abi });
}
}
}
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, decl, abi) {
if should_emit_generic_error(abi, layout_err) {
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
dcx.emit_err(errors::CmseGeneric { span: *fn_sig_span, abi });
}
}
}
@@ -152,8 +152,9 @@ fn is_valid_cmse_output<'tcx>(
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
//
// see also https://github.com/rust-lang/rust/issues/147242.
if return_type.has_opaque_types() {
return Err(tcx.arena.alloc(LayoutError::TooGeneric(return_type)));
if abi == ExternAbi::CmseNonSecureEntry && return_type.has_opaque_types() {
dcx.emit_err(errors::CmseImplTrait { span: fn_decl.output.span(), abi });
return Ok(());
}
let typing_env = ty::TypingEnv::fully_monomorphized();