Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive of box_default #9639

Closed
BusyJay opened this issue Oct 13, 2022 · 1 comment
Closed

False positive of box_default #9639

BusyJay opened this issue Oct 13, 2022 · 1 comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@BusyJay
Copy link

BusyJay commented Oct 13, 2022

Summary

Box::default() will not work if the input is Box<dyn trait>.

Lint Name

box_default

Reproducer

I tried this code:

fn check(_: Box<dyn Send>) {}

fn main() {
    check(Box::new(u64::default())); // vs check(Box::default());
}

I saw this happen:

warning: `Box::new(_)` of default value
 --> src/main.rs:4:11
  |
4 |     check(Box::new(u64::default())); // vs check(Box::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` (bin "playground") generated 1 warning

I expected to see this happen:
Compile OK.

Version

0.1.66 (2022-10-12 c0983a9)

Additional Labels

No response

@BusyJay BusyJay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Oct 13, 2022
@llogiq
Copy link
Contributor

llogiq commented Oct 13, 2022

This is a duplicate of #9621 which by the way already has a not yet merged solution in #9622 and in fact the current master should already have a suggestion to use Box::<u64>::default().

@llogiq llogiq closed this as completed Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants