Skip to content

Commit 98d3864

Browse files
committed
cmse: rephrase error message when signature uses generics
1 parent b47de64 commit 98d3864

File tree

6 files changed

+46
-52
lines changed

6 files changed

+46
-52
lines changed

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ hir_analysis_cannot_capture_late_bound_ty =
7272
hir_analysis_closure_implicit_hrtb = implicit types in closure signatures are forbidden when `for<...>` is present
7373
.label = `for<...>` is here
7474
75-
hir_analysis_cmse_call_generic =
76-
function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
75+
hir_analysis_cmse_generic =
76+
generics are not allowed in `extern {$abi}` signatures
7777
78-
hir_analysis_cmse_entry_generic =
79-
functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
78+
hir_analysis_cmse_impl_trait =
79+
`impl Trait` is not allowed in `extern {$abi}` signatures
8080
8181
hir_analysis_cmse_inputs_stack_spill =
8282
arguments for `{$abi}` function too large to pass via registers

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,22 +1632,24 @@ pub(crate) struct CmseOutputStackSpill {
16321632
}
16331633

16341634
#[derive(Diagnostic)]
1635-
#[diag(hir_analysis_cmse_call_generic, code = E0798)]
1636-
pub(crate) struct CmseCallGeneric {
1635+
#[diag(hir_analysis_cmse_generic, code = E0798)]
1636+
pub(crate) struct CmseGeneric {
16371637
#[primary_span]
16381638
pub span: Span,
1639+
pub abi: ExternAbi,
16391640
}
16401641

16411642
#[derive(Diagnostic)]
1642-
#[diag(hir_analysis_bad_return_type_notation_position)]
1643-
pub(crate) struct BadReturnTypeNotation {
1643+
#[diag(hir_analysis_cmse_impl_trait, code = E0798)]
1644+
pub(crate) struct CmseImplTrait {
16441645
#[primary_span]
16451646
pub span: Span,
1647+
pub abi: ExternAbi,
16461648
}
16471649

16481650
#[derive(Diagnostic)]
1649-
#[diag(hir_analysis_cmse_entry_generic, code = E0798)]
1650-
pub(crate) struct CmseEntryGeneric {
1651+
#[diag(hir_analysis_bad_return_type_notation_position)]
1652+
pub(crate) struct BadReturnTypeNotation {
16511653
#[primary_span]
16521654
pub span: Span,
16531655
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ pub(crate) fn validate_cmse_abi<'tcx>(
4848
Ok(()) => {}
4949
Err(layout_err) => {
5050
if should_emit_generic_error(abi, layout_err) {
51-
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
51+
dcx.emit_err(errors::CmseGeneric { span: *fn_ptr_span, abi });
5252
}
5353
}
5454
}
5555

5656
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, fn_ptr_ty.decl, abi) {
5757
if should_emit_generic_error(abi, layout_err) {
58-
dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span });
58+
dcx.emit_err(errors::CmseGeneric { span: *fn_ptr_span, abi });
5959
}
6060
}
6161
}
@@ -76,14 +76,14 @@ pub(crate) fn validate_cmse_abi<'tcx>(
7676
Ok(()) => {}
7777
Err(layout_err) => {
7878
if should_emit_generic_error(abi, layout_err) {
79-
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
79+
dcx.emit_err(errors::CmseGeneric { span: *fn_sig_span, abi });
8080
}
8181
}
8282
}
8383

8484
if let Err(layout_err) = is_valid_cmse_output(tcx, dcx, fn_sig, decl, abi) {
8585
if should_emit_generic_error(abi, layout_err) {
86-
dcx.emit_err(errors::CmseEntryGeneric { span: *fn_sig_span });
86+
dcx.emit_err(errors::CmseGeneric { span: *fn_sig_span, abi });
8787
}
8888
}
8989
}
@@ -152,8 +152,9 @@ fn is_valid_cmse_output<'tcx>(
152152
// `#[no_mangle]` or similar, so generics in the type really don't make sense.
153153
//
154154
// see also https://github.com/rust-lang/rust/issues/147242.
155-
if return_type.has_opaque_types() {
156-
return Err(tcx.arena.alloc(LayoutError::TooGeneric(return_type)));
155+
if abi == ExternAbi::CmseNonSecureEntry && return_type.has_opaque_types() {
156+
dcx.emit_err(errors::CmseImplTrait { span: fn_decl.output.span(), abi });
157+
return Ok(());
157158
}
158159

159160
let typing_env = ty::TypingEnv::fully_monomorphized();

tests/ui/cmse-nonsecure/cmse-nonsecure-call/generics.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ LL | f3: extern "cmse-nonsecure-call" fn((impl Copy, u32), u32, u32, u32) ->
5454
|
5555
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
5656

57-
error[E0798]: function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
57+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-call"` signatures
5858
--> $DIR/generics.rs:23:9
5959
|
6060
LL | f4: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64,
6161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6262

63-
error[E0798]: function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
63+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-call"` signatures
6464
--> $DIR/generics.rs:24:9
6565
|
6666
LL | f5: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64,

tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,25 @@ extern "cmse-nonsecure-entry" fn impl_trait(_: impl Copy, _: u32, _: u32, _: u32
6767
}
6868

6969
extern "cmse-nonsecure-entry" fn return_impl_trait() -> impl Copy {
70-
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
70+
//~^ ERROR `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
7171
0u128
7272
}
7373

7474
extern "cmse-nonsecure-entry" fn return_impl_trait_nested() -> (impl Copy, i32) {
75-
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
75+
//~^ ERROR `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
7676
(0u128, 0i32)
7777
}
7878

7979
extern "cmse-nonsecure-entry" fn identity_impl_trait(v: impl Copy) -> impl Copy {
80-
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
81-
//~| ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
80+
//~^ ERROR generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
81+
//~| ERROR `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
8282
v
8383
}
8484

8585
extern "cmse-nonsecure-entry" fn identity_impl_trait_nested(
86-
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
87-
//~| ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
86+
//~^ ERROR generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
8887
v: (impl Copy, i32),
8988
) -> (impl Copy, i32) {
89+
//~^ ERROR `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
9090
v
9191
}

tests/ui/cmse-nonsecure/cmse-nonsecure-entry/generics.stderr

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
1+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
22
--> $DIR/generics.rs:30:1
33
|
44
LL | / extern "cmse-nonsecure-entry" fn introduced_generic<U: Copy>(
@@ -10,55 +10,46 @@ LL | | _: u32,
1010
LL | | ) -> u64 {
1111
| |________^
1212

13-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
13+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
1414
--> $DIR/generics.rs:64:1
1515
|
1616
LL | extern "cmse-nonsecure-entry" fn impl_trait(_: impl Copy, _: u32, _: u32, _: u32) -> u64 {
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
19+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
2020
--> $DIR/generics.rs:79:1
2121
|
2222
LL | extern "cmse-nonsecure-entry" fn identity_impl_trait(v: impl Copy) -> impl Copy {
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

25-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
26-
--> $DIR/generics.rs:79:1
25+
error[E0798]: `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
26+
--> $DIR/generics.rs:79:71
2727
|
2828
LL | extern "cmse-nonsecure-entry" fn identity_impl_trait(v: impl Copy) -> impl Copy {
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30-
|
31-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
29+
| ^^^^^^^^^
3230

33-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
31+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
3432
--> $DIR/generics.rs:85:1
3533
|
3634
LL | / extern "cmse-nonsecure-entry" fn identity_impl_trait_nested(
3735
LL | |
38-
LL | |
3936
LL | | v: (impl Copy, i32),
4037
LL | | ) -> (impl Copy, i32) {
4138
| |_____________________^
4239

43-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
44-
--> $DIR/generics.rs:85:1
40+
error[E0798]: `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
41+
--> $DIR/generics.rs:88:6
4542
|
46-
LL | / extern "cmse-nonsecure-entry" fn identity_impl_trait_nested(
47-
LL | |
48-
LL | |
49-
LL | | v: (impl Copy, i32),
50-
LL | | ) -> (impl Copy, i32) {
51-
| |_____________________^
52-
|
53-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
43+
LL | ) -> (impl Copy, i32) {
44+
| ^^^^^^^^^^^^^^^^
5445

55-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
46+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
5647
--> $DIR/generics.rs:14:5
5748
|
5849
LL | extern "cmse-nonsecure-entry" fn ambient_generic(_: T, _: u32, _: u32, _: u32) -> u64 {
5950
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6051

61-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
52+
error[E0798]: generics are not allowed in `extern "cmse-nonsecure-entry"` signatures
6253
--> $DIR/generics.rs:19:5
6354
|
6455
LL | / extern "cmse-nonsecure-entry" fn ambient_generic_nested(
@@ -97,17 +88,17 @@ LL | extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent
9788
= note: functions with the `"cmse-nonsecure-entry"` ABI must pass their result via the available return registers
9889
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
9990

100-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
101-
--> $DIR/generics.rs:69:1
91+
error[E0798]: `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
92+
--> $DIR/generics.rs:69:57
10293
|
10394
LL | extern "cmse-nonsecure-entry" fn return_impl_trait() -> impl Copy {
104-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
95+
| ^^^^^^^^^
10596

106-
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
107-
--> $DIR/generics.rs:74:1
97+
error[E0798]: `impl Trait` is not allowed in `extern "cmse-nonsecure-entry"` signatures
98+
--> $DIR/generics.rs:74:64
10899
|
109100
LL | extern "cmse-nonsecure-entry" fn return_impl_trait_nested() -> (impl Copy, i32) {
110-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
101+
| ^^^^^^^^^^^^^^^^
111102

112103
error: aborting due to 13 previous errors
113104

0 commit comments

Comments
 (0)