False positive for box_default in #![no_std] crate · Issue #9653 · rust-lang/rust-clippy (original) (raw)

Summary

box_default fires in the Default impl of Box-like types in a #![no_std] crate

Lint Name

box_default

Reproducer

I tried this code: (Playground link)

#![no_std]

pub struct NotBox { _value: T, }

impl NotBox { pub fn new(value: T) -> Self { Self { _value: value, } } }

impl<T: Default> Default for NotBox { fn default() -> Self { Self::new(T::default()) } }

I saw this happen:

    Checking playground v0.0.1 (/playground)
warning: `Box::new(_)` of default value
  --> src/lib.rs:17:9
   |
17 |         Self::new(T::default())
   |         ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: use `Box::default()` instead
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#box_default
   = note: `#[warn(clippy::box_default)]` on by default

warning: `playground` (lib) generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.97s

I expected to see this happen:
no output

Version

rustc 1.66.0-nightly (bf15a9e52 2022-10-14)
binary: rustc
commit-hash: bf15a9e5263fcea065a7ae9c179b2d24c2deb670
commit-date: 2022-10-14
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2

Additional Labels

No response