Skip to content

Clippy --fix for box_default creates invalid code #10089

@nsabovic

Description

@nsabovic

After upgrading to 1.66 I got a few new clippy errors. Running clippy --fix produced this error instructing me to file a bug report.

Seems like it attempted to convert:

let _: Box<dyn Trait> = Box::new(ConcreteType::default());

with

let _: Box<dyn Trait> = Box::default();

...which obviously fails.

warning: failed to automatically apply fixes suggested by rustc to crate `optimization` after fixes were automatically applied the compiler reported errors within these files: * optimization/src/driver.rs This likely indicates a bug in either rustc or cargo itself, and we would appreciate a bug report! You're likely to see  a number of compiler warnings after this message which cargo attempted to fix but failed. If you could open an issue at https://github.com/rust-lang/rust/issues quoting the full output of this command we'd be very appreciative! Note that you may be able to make some more progress in the near-term fixing code with the `--broken-code` flag The following errors were reported: error[E0277]: the trait bound `dyn optimizer::Optimizer + std::marker::Send + std::marker::Sync: std::default::Default` is not satisfied --> optimization/src/driver.rs:80:13 | 80 | Box::default(), | ^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `dyn optimizer::Optimizer + std::marker::Send + std::marker::Sync` | = help: the following other types implement trait `std::default::Default`: std::boxed::Box<T> std::boxed::Box<[T]> std::boxed::Box<std::ffi::CStr> std::boxed::Box<std::ffi::OsStr> std::boxed::Box<str> = note: required for `std::boxed::Box<dyn optimizer::Optimizer + std::marker::Send + std::marker::Sync>` to implement `std::default::Default` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. Original diagnostics will follow. Fixed zemax/src/from_zemax/tests/mod.rs (1 fix) warning: `Box::new(_)` of default value --> optimization/src/driver.rs:80:13 | 80 | Box::new(NadamOptimizer::default()), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::default()`  |  = 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions