Disable unused variable lint for naked functions
In most calling conventions, accessing function parameters may require stack access. However, naked functions have no assembly prelude to set up stack access. This is why naked functions may only contain a single `asm!()` block. All parameter access is done inside the `asm!()` block, so we cannot validate the liveness of the input parameters. Therefore, we should disable the lint for naked functions. rust-lang/rfcs#2774 rust-lang/rfcs#2972
This commit is contained in:
parent
7ac0cb0ec1
commit
9c0147c02d
3 changed files with 6 additions and 71 deletions
|
@ -332,6 +332,11 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
// Don't run unused pass for #[naked]
|
||||
if self.tcx.has_attr(def_id, sym::naked) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(captures) = maps.tcx.typeck(local_def_id).closure_min_captures.get(&def_id) {
|
||||
for &var_hir_id in captures.keys() {
|
||||
let var_name = maps.tcx.hir().name(var_hir_id);
|
||||
|
|
|
@ -50,8 +50,6 @@ pub mod normal {
|
|||
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)); }
|
||||
}
|
||||
|
||||
|
@ -60,15 +58,11 @@ pub mod 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)); }
|
||||
}
|
||||
}
|
||||
|
@ -76,15 +70,11 @@ pub mod naked {
|
|||
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)); }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,65 +65,5 @@ error: unused variable: `b`
|
|||
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
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue