Skip to content

Commit a507ec6

Browse files
committed
add uitest for naked functions and the repr attr on functions
1 parent c3000ad commit a507ec6

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@ needs-asm-support
2+
#![feature(naked_functions)]
3+
#![feature(fn_align)]
4+
#![crate_type = "lib"]
5+
use std::arch::asm;
6+
7+
#[repr(C)]
8+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
9+
#[naked]
10+
extern "C" fn example1() {
11+
//~^ NOTE not a struct, enum, or union
12+
unsafe { asm!("", options(noreturn)) }
13+
}
14+
15+
#[repr(transparent)]
16+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
17+
#[naked]
18+
extern "C" fn example2() {
19+
//~^ NOTE not a struct, enum, or union
20+
unsafe { asm!("", options(noreturn)) }
21+
}
22+
23+
#[repr(align(16), C)]
24+
//~^ ERROR attribute should be applied to a struct, enum, or union [E0517]
25+
#[naked]
26+
extern "C" fn example3() {
27+
//~^ NOTE not a struct, enum, or union
28+
unsafe { asm!("", options(noreturn)) }
29+
}
30+
31+
// note: two errors because of packed and C
32+
#[repr(C, packed)]
33+
//~^ ERROR attribute should be applied to a struct or union [E0517]
34+
//~| ERROR attribute should be applied to a struct, enum, or union [E0517]
35+
#[naked]
36+
extern "C" fn example4() {
37+
//~^ NOTE not a struct, enum, or union
38+
//~| NOTE not a struct or union
39+
unsafe { asm!("", options(noreturn)) }
40+
}
41+
42+
#[repr(u8)]
43+
//~^ ERROR attribute should be applied to an enum [E0517]
44+
#[naked]
45+
extern "C" fn example5() {
46+
//~^ NOTE not an enum
47+
unsafe { asm!("", options(noreturn)) }
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
error[E0517]: attribute should be applied to a struct, enum, or union
2+
--> $DIR/naked-with-invalid-repr-attr.rs:7:8
3+
|
4+
LL | #[repr(C)]
5+
| ^
6+
...
7+
LL | / extern "C" fn example1() {
8+
LL | |
9+
LL | | unsafe { asm!("", options(noreturn)) }
10+
LL | | }
11+
| |_- not a struct, enum, or union
12+
13+
error[E0517]: attribute should be applied to a struct, enum, or union
14+
--> $DIR/naked-with-invalid-repr-attr.rs:15:8
15+
|
16+
LL | #[repr(transparent)]
17+
| ^^^^^^^^^^^
18+
...
19+
LL | / extern "C" fn example2() {
20+
LL | |
21+
LL | | unsafe { asm!("", options(noreturn)) }
22+
LL | | }
23+
| |_- not a struct, enum, or union
24+
25+
error[E0517]: attribute should be applied to a struct, enum, or union
26+
--> $DIR/naked-with-invalid-repr-attr.rs:23:19
27+
|
28+
LL | #[repr(align(16), C)]
29+
| ^
30+
...
31+
LL | / extern "C" fn example3() {
32+
LL | |
33+
LL | | unsafe { asm!("", options(noreturn)) }
34+
LL | | }
35+
| |_- not a struct, enum, or union
36+
37+
error[E0517]: attribute should be applied to a struct, enum, or union
38+
--> $DIR/naked-with-invalid-repr-attr.rs:32:8
39+
|
40+
LL | #[repr(C, packed)]
41+
| ^
42+
...
43+
LL | / extern "C" fn example4() {
44+
LL | |
45+
LL | |
46+
LL | | unsafe { asm!("", options(noreturn)) }
47+
LL | | }
48+
| |_- not a struct, enum, or union
49+
50+
error[E0517]: attribute should be applied to a struct or union
51+
--> $DIR/naked-with-invalid-repr-attr.rs:32:11
52+
|
53+
LL | #[repr(C, packed)]
54+
| ^^^^^^
55+
...
56+
LL | / extern "C" fn example4() {
57+
LL | |
58+
LL | |
59+
LL | | unsafe { asm!("", options(noreturn)) }
60+
LL | | }
61+
| |_- not a struct or union
62+
63+
error[E0517]: attribute should be applied to an enum
64+
--> $DIR/naked-with-invalid-repr-attr.rs:42:8
65+
|
66+
LL | #[repr(u8)]
67+
| ^^
68+
...
69+
LL | / extern "C" fn example5() {
70+
LL | |
71+
LL | | unsafe { asm!("", options(noreturn)) }
72+
LL | | }
73+
| |_- not an enum
74+
75+
error: aborting due to 6 previous errors
76+
77+
For more information about this error, try `rustc --explain E0517`.

0 commit comments

Comments
 (0)