Skip to content

Exclude self-by-value trait methods implemented on Box<T> from boxed_local #1478

Closed
@dtolnay

Description

@dtolnay

Simplest case:

trait Trait {
    fn f(self);
}

impl<T> Trait for Box<T> {
    fn f(self) {}
}
warning: local variable doesn't need to be boxed here, #[warn(boxed_local)] on by default
 --> src/main.rs:9:10
  |
9 |     fn f(self) {}
  |          ^^^^

More realistic case that we hit in dtolnay/syn#85:

trait LiftOnce<T, U> {
    type Output;
    fn lift<F>(self, f: F) -> Self::Output where F: FnOnce(T) -> U;
}

impl<T, U> LiftOnce<T, U> for Box<T> {
    type Output = Box<U>;
    fn lift<F>(self, f: F) -> Box<U> where F: FnOnce(T) -> U {
        Box::new(f(*self))
    }
}

I would consider this a false positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions