-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Description
use std::marker::PhantomData;
struct TypeWithoutDefault;
#[derive(Default)]
struct NewType<T>(PhantomData<T>);
fn main() {
let _ = NewType::<TypeWithoutDefault>::default();
// ^ E0599
// no function or associated item named `default` found
// for type `NewType<TypeWithoutDefault>` in the current scope
}But if we implement Default without derive:
impl<T> Default for NewType<T> {
fn default() -> Self {
Self(PhantomData)
}
}Then code compiles successfully.
Can derive(Default) be smarter for cases like this?
Metadata
Metadata
Assignees
Labels
No labels