Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require impl generic parameters be constrained by the trait def #57

Open
nikomatsakis opened this issue Jun 16, 2022 · 2 comments
Open
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@nikomatsakis
Copy link
Contributor

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
@nikomatsakis nikomatsakis added bug Something isn't working good first issue Good for newcomers labels Jun 16, 2022
@nikomatsakis
Copy link
Contributor Author

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).

@nikomatsakis
Copy link
Contributor Author

In other words, I would just define these rules using redex type judgments, not try to make logical predicates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant