Skip to content

Commit f62be66

Browse files
committed
cmse: additional impl Trait tests
1 parent d62f33a commit f62be66

File tree

5 files changed

+88
-37
lines changed

5 files changed

+88
-37
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn should_emit_generic_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError
216216
match abi {
217217
ExternAbi::CmseNonSecureCall => {
218218
// prevent double reporting of this error
219-
!ty.is_impl_trait()
219+
!ty.has_opaque_types()
220220
}
221221
ExternAbi::CmseNonSecureEntry => true,
222222
_ => bug!("invalid ABI: {abi}"),

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ struct Test<T: Copy> {
1717
f2: extern "cmse-nonsecure-call" fn(impl Copy, u32, u32, u32) -> impl Copy,
1818
//~^ ERROR `impl Trait` is not allowed in `fn` pointer parameters
1919
//~| ERROR `impl Trait` is not allowed in `fn` pointer return types
20-
f3: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64, //~ ERROR [E0798]
21-
f4: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64, //~ ERROR [E0798]
20+
f3: extern "cmse-nonsecure-call" fn((impl Copy, u32), u32, u32, u32) -> (impl Copy, u32),
21+
//~^ ERROR `impl Trait` is not allowed in `fn` pointer parameters
22+
//~| ERROR `impl Trait` is not allowed in `fn` pointer return types
23+
f4: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64, //~ ERROR [E0798]
24+
f5: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64, //~ ERROR [E0798]
2225
}
2326

2427
type WithReference = extern "cmse-nonsecure-call" fn(&usize);

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,36 @@ LL | f2: extern "cmse-nonsecure-call" fn(impl Copy, u32, u32, u32) -> impl C
3838
|
3939
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
4040

41+
error[E0562]: `impl Trait` is not allowed in `fn` pointer parameters
42+
--> $DIR/generics.rs:20:42
43+
|
44+
LL | f3: extern "cmse-nonsecure-call" fn((impl Copy, u32), u32, u32, u32) -> (impl Copy, u32),
45+
| ^^^^^^^^^
46+
|
47+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
48+
49+
error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
50+
--> $DIR/generics.rs:20:78
51+
|
52+
LL | f3: extern "cmse-nonsecure-call" fn((impl Copy, u32), u32, u32, u32) -> (impl Copy, u32),
53+
| ^^^^^^^^^
54+
|
55+
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
56+
4157
error[E0798]: function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
42-
--> $DIR/generics.rs:20:9
58+
--> $DIR/generics.rs:23:9
4359
|
44-
LL | f3: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64,
60+
LL | f4: extern "cmse-nonsecure-call" fn(T, u32, u32, u32) -> u64,
4561
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4662

4763
error[E0798]: function pointers with the `"cmse-nonsecure-call"` ABI cannot contain generics in their type
48-
--> $DIR/generics.rs:21:9
64+
--> $DIR/generics.rs:24:9
4965
|
50-
LL | f4: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64,
66+
LL | f5: extern "cmse-nonsecure-call" fn(Wrapper<T>, u32, u32, u32) -> u64,
5167
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5268

5369
error[E0798]: return value of `"cmse-nonsecure-call"` function too large to pass via registers
54-
--> $DIR/generics.rs:27:71
70+
--> $DIR/generics.rs:30:71
5571
|
5672
LL | type WithTraitObject = extern "cmse-nonsecure-call" fn(&dyn Trait) -> &dyn Trait;
5773
| ^^^^^^^^^^ this type doesn't fit in the available registers
@@ -60,7 +76,7 @@ LL | type WithTraitObject = extern "cmse-nonsecure-call" fn(&dyn Trait) -> &dyn
6076
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
6177

6278
error[E0798]: return value of `"cmse-nonsecure-call"` function too large to pass via registers
63-
--> $DIR/generics.rs:31:60
79+
--> $DIR/generics.rs:34:60
6480
|
6581
LL | extern "cmse-nonsecure-call" fn(&'static dyn Trait) -> &'static dyn Trait;
6682
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
@@ -69,7 +85,7 @@ LL | extern "cmse-nonsecure-call" fn(&'static dyn Trait) -> &'static dyn Tra
6985
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
7086

7187
error[E0798]: return value of `"cmse-nonsecure-call"` function too large to pass via registers
72-
--> $DIR/generics.rs:38:60
88+
--> $DIR/generics.rs:41:60
7389
|
7490
LL | extern "cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTransparent;
7591
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
@@ -78,12 +94,12 @@ LL | extern "cmse-nonsecure-call" fn(WrapperTransparent) -> WrapperTranspare
7894
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
7995

8096
error[E0045]: C-variadic functions with the "cmse-nonsecure-call" calling convention are not supported
81-
--> $DIR/generics.rs:41:20
97+
--> $DIR/generics.rs:44:20
8298
|
8399
LL | type WithVarArgs = extern "cmse-nonsecure-call" fn(u32, ...);
84100
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadic function must have a compatible calling convention
85101

86-
error: aborting due to 10 previous errors
102+
error: aborting due to 12 previous errors
87103

88104
Some errors have detailed explanations: E0045, E0412, E0562, E0798.
89105
For more information about an error, try `rustc --explain E0045`.

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ extern "cmse-nonsecure-entry" fn introduced_generic<U: Copy>(
3737
0
3838
}
3939

40-
extern "cmse-nonsecure-entry" fn impl_trait(_: impl Copy, _: u32, _: u32, _: u32) -> u64 {
41-
//~^ ERROR [E0798]
42-
0
43-
}
44-
4540
extern "cmse-nonsecure-entry" fn reference(x: &usize) -> usize {
4641
*x
4742
}
@@ -66,14 +61,31 @@ extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent) ->
6661
x
6762
}
6863

69-
extern "cmse-nonsecure-entry" fn return_impl_trait(_: impl Copy) -> impl Copy {
64+
extern "cmse-nonsecure-entry" fn impl_trait(_: impl Copy, _: u32, _: u32, _: u32) -> u64 {
65+
//~^ ERROR [E0798]
66+
0
67+
}
68+
69+
extern "cmse-nonsecure-entry" fn return_impl_trait() -> impl Copy {
7070
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
71-
//~| ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
7271
0u128
7372
}
7473

75-
extern "cmse-nonsecure-entry" fn return_impl_trait_nested(v: (impl Copy, i32)) -> (impl Copy, i32) {
74+
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
76+
(0u128, 0i32)
77+
}
78+
79+
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
82+
v
83+
}
84+
85+
extern "cmse-nonsecure-entry" fn identity_impl_trait_nested(
7686
//~^ ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
7787
//~| ERROR functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
88+
v: (impl Copy, i32),
89+
) -> (impl Copy, i32) {
7890
v
7991
}

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

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,44 @@ LL | | ) -> u64 {
1111
| |________^
1212

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

1919
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
20-
--> $DIR/generics.rs:69:1
20+
--> $DIR/generics.rs:79:1
2121
|
22-
LL | extern "cmse-nonsecure-entry" fn return_impl_trait(_: impl Copy) -> impl Copy {
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
LL | extern "cmse-nonsecure-entry" fn identity_impl_trait(v: impl Copy) -> impl Copy {
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
26-
--> $DIR/generics.rs:69:1
26+
--> $DIR/generics.rs:79:1
2727
|
28-
LL | extern "cmse-nonsecure-entry" fn return_impl_trait(_: impl Copy) -> impl Copy {
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
LL | extern "cmse-nonsecure-entry" fn identity_impl_trait(v: impl Copy) -> impl Copy {
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
3232

3333
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
34-
--> $DIR/generics.rs:75:1
34+
--> $DIR/generics.rs:85:1
3535
|
36-
LL | extern "cmse-nonsecure-entry" fn return_impl_trait_nested(v: (impl Copy, i32)) -> (impl Copy, i32) {
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
LL | / extern "cmse-nonsecure-entry" fn identity_impl_trait_nested(
37+
LL | |
38+
LL | |
39+
LL | | v: (impl Copy, i32),
40+
LL | | ) -> (impl Copy, i32) {
41+
| |_____________________^
3842

3943
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
40-
--> $DIR/generics.rs:75:1
44+
--> $DIR/generics.rs:85:1
4145
|
42-
LL | extern "cmse-nonsecure-entry" fn return_impl_trait_nested(v: (impl Copy, i32)) -> (impl Copy, i32) {
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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+
| |_____________________^
4452
|
4553
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
4654

@@ -63,7 +71,7 @@ LL | | ) -> u64 {
6371
| |____________^
6472

6573
error[E0798]: return value of `"cmse-nonsecure-entry"` function too large to pass via registers
66-
--> $DIR/generics.rs:51:65
74+
--> $DIR/generics.rs:46:65
6775
|
6876
LL | extern "cmse-nonsecure-entry" fn trait_object(x: &dyn Trait) -> &dyn Trait {
6977
| ^^^^^^^^^^ this type doesn't fit in the available registers
@@ -72,7 +80,7 @@ LL | extern "cmse-nonsecure-entry" fn trait_object(x: &dyn Trait) -> &dyn Trait
7280
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
7381

7482
error[E0798]: return value of `"cmse-nonsecure-entry"` function too large to pass via registers
75-
--> $DIR/generics.rs:56:80
83+
--> $DIR/generics.rs:51:80
7684
|
7785
LL | extern "cmse-nonsecure-entry" fn static_trait_object(x: &'static dyn Trait) -> &'static dyn Trait {
7886
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
@@ -81,14 +89,26 @@ LL | extern "cmse-nonsecure-entry" fn static_trait_object(x: &'static dyn Trait)
8189
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
8290

8391
error[E0798]: return value of `"cmse-nonsecure-entry"` function too large to pass via registers
84-
--> $DIR/generics.rs:64:81
92+
--> $DIR/generics.rs:59:81
8593
|
8694
LL | extern "cmse-nonsecure-entry" fn wrapped_trait_object(x: WrapperTransparent) -> WrapperTransparent {
8795
| ^^^^^^^^^^^^^^^^^^ this type doesn't fit in the available registers
8896
|
8997
= note: functions with the `"cmse-nonsecure-entry"` ABI must pass their result via the available return registers
9098
= note: the result must either be a (transparently wrapped) i64, u64 or f64, or be at most 4 bytes in size
9199

92-
error: aborting due to 11 previous errors
100+
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
101+
--> $DIR/generics.rs:69:1
102+
|
103+
LL | extern "cmse-nonsecure-entry" fn return_impl_trait() -> impl Copy {
104+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105+
106+
error[E0798]: functions with the `"cmse-nonsecure-entry"` ABI cannot contain generics in their type
107+
--> $DIR/generics.rs:74:1
108+
|
109+
LL | extern "cmse-nonsecure-entry" fn return_impl_trait_nested() -> (impl Copy, i32) {
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111+
112+
error: aborting due to 13 previous errors
93113

94114
For more information about this error, try `rustc --explain E0798`.

0 commit comments

Comments
 (0)