RS.CLIPPY.NEW_WITHOUT_DEFAULT
`pub fn new() -> Self` method without `Default` implementation
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: new_without_default. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for public types with a pub fn new() -> Self method and no
implementation of
Default.
Why is this bad?
The user might expect to be able to use
Default as the
type can be constructed without arguments.
Example
pub struct Foo(Bar);
impl Foo {
pub fn new() -> Self {
Foo(Bar::new())
}
}
To fix the lint, add a Default implementation that delegates to new:
pub struct Foo(Bar);
impl Default for Foo {
fn default() -> Self {
Foo::new()
}
}
Past names
- new_without_default_derive