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:
Nathaniel McCallum 2021-08-03 16:45:55 -04:00
parent 7ac0cb0ec1
commit 9c0147c02d
3 changed files with 6 additions and 71 deletions

View file

@ -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);