Skip to content

new_without_default_derive False Positive #2226

Closed
@oxalica

Description

@oxalica

It seems deriving Default on struct with generic type and lifetime restriction will cause it.
In this example, clippy 0.0.171 suggests me to add #[derive(Default)] again.

#[derive(Default)]
pub struct S<'a, T: 'a>(Option<&'a T>);

// Manually impl (remove `#[derive(Default)]`) works as expected.
// impl<'a, T: 'a> Default for S<'a, T> {
//     fn default() -> Self {
//         S::new()
//     }
// }

impl<'a, T: 'a> S<'a, T> {
    pub fn new() -> Self { 
        S(None) 
    }
}

fn main() {
    let _ = S::<i32>::default(); // works
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions