Description
I haven't thought this through fully, but I feel like it should be possible (by definition) for the compiler to act as if !
implemented every trait, or rather, to ignore errors about it not implementing a particular trait.
e.g. given this definition of an enum:
enum Style<T>
where
T: SomeTrait,
{
Variant1,
Variant2(T),
}
I propose that it should be valid to use Style<!>
directly, so long as one is not instantiating an instance of type Style::Variant2
, which would in turn make this legal:
enum Style<T=!>
where
T: SomeTrait,
{
Variant1,
Variant2(T),
}
Since !
cannot exist, all of Style::Variant2
cannot exist, in which case it doesn't matter if the generic constraint !: SomeTrait
is not met; thus allowing the use of Style::Variant1
directly without needing to specify a type for T
which will never be used.
With regards to the calculation of the size of the enum: it is provable that Style<!>::Variant2
cannot exist, therefore it should be precluded from the calculation of the size of the type, and treated as a phantom variant with no bearing on the object size. In fact, in the case of such a binary enum with only two types, one of which is purely phantom, the entire enum should be optimized away and it should be treated as a zero-size type altogether (or else the size of Variant1
should Variant1
have any associated values).