Skip to content

Commit 7ac0cb0

Browse files
committed
Add test for naked function unused variables lint
This test proves that naked functions are treated the same as regular functions regarding unused function parameters. We will change this behavior in the next patch.
1 parent 6fe0886 commit 7ac0cb0

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// only-x86_64
2+
#![deny(unused)]
3+
#![feature(asm)]
4+
#![feature(naked_functions)]
5+
#![crate_type = "lib"]
6+
7+
pub trait Trait {
8+
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize;
9+
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize;
10+
}
11+
12+
pub mod normal {
13+
pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
14+
//~^ ERROR unused variable: `a`
15+
//~| ERROR unused variable: `b`
16+
unsafe { asm!("", options(noreturn)); }
17+
}
18+
19+
pub struct Normal;
20+
21+
impl Normal {
22+
pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
23+
//~^ ERROR unused variable: `a`
24+
//~| ERROR unused variable: `b`
25+
unsafe { asm!("", options(noreturn)); }
26+
}
27+
28+
pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
29+
//~^ ERROR unused variable: `a`
30+
//~| ERROR unused variable: `b`
31+
unsafe { asm!("", options(noreturn)); }
32+
}
33+
}
34+
35+
impl super::Trait for Normal {
36+
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
37+
//~^ ERROR unused variable: `a`
38+
//~| ERROR unused variable: `b`
39+
unsafe { asm!("", options(noreturn)); }
40+
}
41+
42+
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
43+
//~^ ERROR unused variable: `a`
44+
//~| ERROR unused variable: `b`
45+
unsafe { asm!("", options(noreturn)); }
46+
}
47+
}
48+
}
49+
50+
pub mod naked {
51+
#[naked]
52+
pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
53+
//~^ ERROR unused variable: `a`
54+
//~| ERROR unused variable: `b`
55+
unsafe { asm!("", options(noreturn)); }
56+
}
57+
58+
pub struct Naked;
59+
60+
impl Naked {
61+
#[naked]
62+
pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
63+
//~^ ERROR unused variable: `a`
64+
//~| ERROR unused variable: `b`
65+
unsafe { asm!("", options(noreturn)); }
66+
}
67+
68+
#[naked]
69+
pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
70+
//~^ ERROR unused variable: `a`
71+
//~| ERROR unused variable: `b`
72+
unsafe { asm!("", options(noreturn)); }
73+
}
74+
}
75+
76+
impl super::Trait for Naked {
77+
#[naked]
78+
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
79+
//~^ ERROR unused variable: `a`
80+
//~| ERROR unused variable: `b`
81+
unsafe { asm!("", options(noreturn)); }
82+
}
83+
84+
#[naked]
85+
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
86+
//~^ ERROR unused variable: `a`
87+
//~| ERROR unused variable: `b`
88+
unsafe { asm!("", options(noreturn)); }
89+
}
90+
}
91+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
error: unused variable: `a`
2+
--> $DIR/naked-functions-unused.rs:13:37
3+
|
4+
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
5+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/naked-functions-unused.rs:2:9
9+
|
10+
LL | #![deny(unused)]
11+
| ^^^^^^
12+
= note: `#[deny(unused_variables)]` implied by `#[deny(unused)]`
13+
14+
error: unused variable: `b`
15+
--> $DIR/naked-functions-unused.rs:13:47
16+
|
17+
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
18+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
19+
20+
error: unused variable: `a`
21+
--> $DIR/naked-functions-unused.rs:22:43
22+
|
23+
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
24+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
25+
26+
error: unused variable: `b`
27+
--> $DIR/naked-functions-unused.rs:22:53
28+
|
29+
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
30+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
31+
32+
error: unused variable: `a`
33+
--> $DIR/naked-functions-unused.rs:28:46
34+
|
35+
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
36+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
37+
38+
error: unused variable: `b`
39+
--> $DIR/naked-functions-unused.rs:28:56
40+
|
41+
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
42+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
43+
44+
error: unused variable: `a`
45+
--> $DIR/naked-functions-unused.rs:36:45
46+
|
47+
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
48+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
49+
50+
error: unused variable: `b`
51+
--> $DIR/naked-functions-unused.rs:36:55
52+
|
53+
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
54+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
55+
56+
error: unused variable: `a`
57+
--> $DIR/naked-functions-unused.rs:42:48
58+
|
59+
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
60+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
61+
62+
error: unused variable: `b`
63+
--> $DIR/naked-functions-unused.rs:42:58
64+
|
65+
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
66+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
67+
68+
error: unused variable: `a`
69+
--> $DIR/naked-functions-unused.rs:52:37
70+
|
71+
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
72+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
73+
74+
error: unused variable: `b`
75+
--> $DIR/naked-functions-unused.rs:52:47
76+
|
77+
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
78+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
79+
80+
error: unused variable: `a`
81+
--> $DIR/naked-functions-unused.rs:62:43
82+
|
83+
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
84+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
85+
86+
error: unused variable: `b`
87+
--> $DIR/naked-functions-unused.rs:62:53
88+
|
89+
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
90+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
91+
92+
error: unused variable: `a`
93+
--> $DIR/naked-functions-unused.rs:69:46
94+
|
95+
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
96+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
97+
98+
error: unused variable: `b`
99+
--> $DIR/naked-functions-unused.rs:69:56
100+
|
101+
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
102+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
103+
104+
error: unused variable: `a`
105+
--> $DIR/naked-functions-unused.rs:78:45
106+
|
107+
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
108+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
109+
110+
error: unused variable: `b`
111+
--> $DIR/naked-functions-unused.rs:78:55
112+
|
113+
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
114+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
115+
116+
error: unused variable: `a`
117+
--> $DIR/naked-functions-unused.rs:85:48
118+
|
119+
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
120+
| ^ help: if this is intentional, prefix it with an underscore: `_a`
121+
122+
error: unused variable: `b`
123+
--> $DIR/naked-functions-unused.rs:85:58
124+
|
125+
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
126+
| ^ help: if this is intentional, prefix it with an underscore: `_b`
127+
128+
error: aborting due to 20 previous errors
129+

0 commit comments

Comments
 (0)