a-mir-formality
a-mir-formality copied to clipboard
require impl generic parameters be constrained by the trait def
Rust prohibits type parameters in a trait impl that don't appear in the trait definition:
impl<T> Iterator for () { type Item = (); } // ERROR
and unconstrained lifetime parameters that appear in a trait value
impl<'a> Iterator for () { type Item = &'a (); } // ERROR
We need to extend the rules to cover these. Careful, though, some uses of a generic parameter don't count as constrained:
impl<T> Iterator for <T as Iterator>::Item { type Item = (); } // also an ERROR
Probably we want some kind of "well-formed decls" check analogous to well-formed-mir? It could also check that e.g. all TraitId are defined somewhere (which current results in assertion failures).
In other words, I would just define these rules using redex type judgments, not try to make logical predicates.