idanarye / rust-typed-builder

Compile-time type-checked builder derive
https://crates.io/crates/typed-builder
Apache License 2.0
904 stars 52 forks source link

`#[derive(TypedBuilder)]` triggers `clippy::used_underscore_binding` for `_ident: PhantomData<>` #113

Closed xFrednet closed 11 months ago

xFrednet commented 11 months ago

The underscore binding is used for fields, which should not be used. In my project, I often use PhantomData to store a lifetime. This triggers the clippy::used_underscore_binding lint, when deriving TypedBuilder

Reproducer

#![warn(clippy::used_underscore_binding)]

use std::marker::PhantomData;

use typed_builder::TypedBuilder;

#[derive(TypedBuilder)]
pub struct Bar<'ast> {
    #[builder(default)]
    _lifetime: PhantomData<&'ast ()>,
}

And run cargo clippy

Suggestions

I'm not sure, if there is a simple way to fix this. Maybe #[allow(clippy::used_underscore_binding)] would fix it. Another option could be the addition of a new #[builder] attribute, that only sets the value and doesn't allow the user to override it.

These are just some suggestions, there are probably better solutions.