So like, it'd be nice if either of these were a thing:
PDDE
PDDE makes it so the behaviour of #[derive(Default)]
changes for private structs. instead of adding bounds on type parameters, it would add bounds on field types. This is leaky, but because private structs aren't public, it only leaks into private API details... which are private anyway.
Blanket impls for local traits
TL;DR:
trait Foo {
}
impl<T: Foo> Default for T {
fn default() -> T {
panic!("Foo should be uninhabited.")
}
}
Either of these would allow derive(Default)
to work for us: the trait we're dealing with is supposed to be uninhabited anyway, as it doesn't take self
anywhere. and everywhere it's relevant, we have an Option
or some other thing that impls Default
in the way.
Ppl don't seem to want either of them tho. PDDEs get called "too surprising" (when making something pub or private the bounds change - altho honestly we'd say refactoring can break code and you're supposed to fix said breaks when refactoring) or "too leaky" (because it leaks the field types by defining bounds based on them). and blanket impls for local traits are "too restrictive" for downstream crates (which... well, yeah, but that's intended).
Thoughts?