Skip to content

Suggestion does not compile: use self with when implementing From conversion for the Box<dyn Trait>. #4305

Closed
@alekseysidorov

Description

@alekseysidorov
clippy 0.0.212 (082cfa7 2019-06-07)

Clippy incorrectly suggests to use Self when implementing From conversion for the Box<dyn Trait> type.

#![deny(clippy::pedantic)]

trait Foo: 'static {}

struct Bar;

impl Foo for Bar {}

impl<T: Foo> From<T> for Box<dyn Foo> {
    fn from(t: T) -> Self {
        Box::new(t)
    }
}

Results the following error:

unnecessary structure name repetition
#[deny(clippy::use_self)] implied by #[deny(clippy::pedantic)]
for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_selfclippy(use_self)
lib.rs(1, 9): lint level defined here

But code with this suggestion does not compile:

#![deny(clippy::pedantic)]

trait Foo: 'static {}

struct Bar;

impl Foo for Bar {}

impl<T: Foo> From<T> for Box<dyn Foo> {
    fn from(t: T) -> Self {
        Self::new(t)
    }
}
no function or associated item named `new` found for type `std::boxed::Box<(dyn Foo + 'static)>` in the current scope
the method `new` exists but the following trait bounds were not satisfied:
`dyn Foo : std::marker::Sized`

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documentationArea: Adding or improving documentationC-bugCategory: Clippy is not doing the correct thingE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.I-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood 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