Skip to content

Clippy incorrectly complains about borrowed_box when trait object is boxed #3971

Closed
@idubrov

Description

@idubrov

The following code triggers clippy::borrowed_box:

trait Whatever {}
struct Something;
impl Whatever for Something {}
fn func(flag: bool, secret: &mut Box<Whatever>) {
    *secret = Box::new(Something);
}

However, I don't think it should be complaining here since Whatever is not Sized (so I cannot overwrite it directly)

I think, this issue (or similar) was raised before: #1884 (also mentioned in #3128)

The fix for #1884 was, however, just to check for Any trait as a special case.

Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions