4

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?

Ry-
  • 218,210
  • 55
  • 464
  • 476
toku-sa-n
  • 798
  • 1
  • 8
  • 27
  • Could you try cutting more and more of your code until you create a minimal example that still shows the incorrect lint? This would probably be of interest to clippy devs. – user4815162342 Sep 17 '20 at 07:46
  • clippy is not a perfect tool – Stargateur Sep 17 '20 at 07:46
  • 1
    Might be one more instance of [false positives when selecting (... allocator](https://github.com/rust-lang/rust-clippy/issues/2373). Either way a clippy channel of some sort would probably be a better place for this sort of inquiries, I don't know if the clippy community has a discord or discourse though. – Masklinn Sep 17 '20 at 08:00
  • @user4815162342 Thanks for your comment, but I'm totally lost. Clippy suddenly becomes silent after moving a directory, that is, Clippy complains if I run it in ~/Downloads/foo, but after running `cp ~/Downloads/foo ~ -r && cd ~/foo && cargo clean && cargo clippy`, no errors were printed. I saw other clippy's strange behavior. I can't create a reproducible minimum code soon. – toku-sa-n Sep 17 '20 at 12:59
  • @Masklinn The issue seems related, thanks. – toku-sa-n Sep 17 '20 at 13:01

1 Answers1

2

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
abcalphabet
  • 1,158
  • 3
  • 16
  • 31