Clippy says `too many arguments` to static declaration

3.6k views Asked by At

This code is from my OS.

#[global_allocator]
pub static ALLOCATOR: LockedHeap = LockedHeap::empty();

Clippy says this function has too many arguments.

error: this function has too many arguments (4/3)
  --> src/mem/allocator/heap.rs:14:1
   |
14 | pub static ALLOCATOR: LockedHeap = LockedHeap::empty();
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the lint level is defined here
  --> src/lib.rs:14:9
   |
14 | #![deny(clippy::all)]
   |         ^^^^^^^^^^^
   = note: `#[deny(clippy::too_many_arguments)]` implied by `#[deny(clippy::all)]`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
   = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

I thought the cause is global_allocator attribute or linked_list_allocator crate, so I wrote a minimum code using them.

#![deny(clippy::all)]
#![feature(alloc_error_handler)]
#![feature(start)]
#![feature(lang_items)]
#![no_std]

#[global_allocator]
pub static LIST: linked_list_allocator::LockedHeap = linked_list_allocator::LockedHeap::empty();

#[start]
fn _start(c: isize, v: *const *const u8) -> isize {
    3
}

#[alloc_error_handler]
fn oom(_layout: core::alloc::Layout) -> ! {
    panic!()
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

#[lang = "eh_personality"]
fn eh() {}

However, clippy said nothing about this code.

Why does clippy complain about the first code?

1

There are 1 answers

0
abcalphabet On

If clippy complains about this on a normal function declaration use the #[allow(clippy::too_many_arguments)] attribute on said function to get rid of the error.