1
Fork 0

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.
This commit is contained in:
Nathaniel McCallum 2021-08-03 11:19:35 -04:00
parent 6fe0886723
commit 7ac0cb0ec1
2 changed files with 220 additions and 0 deletions

View file

@ -0,0 +1,91 @@
// only-x86_64
#![deny(unused)]
#![feature(asm)]
#![feature(naked_functions)]
#![crate_type = "lib"]
pub trait Trait {
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize;
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize;
}
pub mod normal {
pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
pub struct Normal;
impl Normal {
pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
}
impl super::Trait for Normal {
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
}
}
pub mod naked {
#[naked]
pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
pub struct Naked;
impl Naked {
#[naked]
pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
#[naked]
pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
}
impl super::Trait for Naked {
#[naked]
extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
#[naked]
extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
//~^ ERROR unused variable: `a`
//~| ERROR unused variable: `b`
unsafe { asm!("", options(noreturn)); }
}
}
}

View file

@ -0,0 +1,129 @@
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:13:37
|
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
|
note: the lint level is defined here
--> $DIR/naked-functions-unused.rs:2:9
|
LL | #![deny(unused)]
| ^^^^^^
= note: `#[deny(unused_variables)]` implied by `#[deny(unused)]`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:13:47
|
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:22:43
|
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:22:53
|
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:28:46
|
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:28:56
|
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:36:45
|
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:36:55
|
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:42:48
|
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:42:58
|
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:52:37
|
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:52:47
|
LL | pub extern "sysv64" fn function(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:62:43
|
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:62:53
|
LL | pub extern "sysv64" fn associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:69:46
|
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:69:56
|
LL | pub extern "sysv64" fn method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:78:45
|
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:78:55
|
LL | extern "sysv64" fn trait_associated(a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: unused variable: `a`
--> $DIR/naked-functions-unused.rs:85:48
|
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_a`
error: unused variable: `b`
--> $DIR/naked-functions-unused.rs:85:58
|
LL | extern "sysv64" fn trait_method(&self, a: usize, b: usize) -> usize {
| ^ help: if this is intentional, prefix it with an underscore: `_b`
error: aborting due to 20 previous errors