-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Generic impls rely on syntax too much #1162
Comments
#376 proposes allowing something like |
It is not really based on syntax, but rather on type-constructors. Rust's type system is based on type constructors, and will be in the foreseeable future. |
By non-reference, I assume you mean an owned value that isn't a pointer of any kind (e.g. not &, &mut, *const, or *mut). But these pointers are owned values, and just types like any other type. What about library defined pointer types, like If you mean to implement traits for every type that isn't a particular type, that is a different thing, with other implications. But there's nothing special about a non-reference type any more than non- |
@eefriedman @arielb1
(Negation on type constructors is probably a separate problem, yes.) @withoutboats If Rust gets specialization and sealed traits, then we could copy the C++'s approach to the problem.
Note, that Rust unlike C++ performs type checking before monomorphization, so traits like |
Not really. There's a Anyway, this wouldn't work with traits because we don't support sealed/exclusive traits, and adding that would be rather complicated. |
Rust could recognize other classes of types, say if I wanted to impl a trait for all anonymous lambda expression types, or all tuple types, etc. |
References, raw pointers, arrays etc. have distinct syntactic forms and as a consequence 1) traits can be implemented for them and 2) coherence checker knows things like "references are not arrays"
On the other side, trait objects, non-references, non-pointers, unique function types, tuples of any size and other sets of types don't have distinct syntactic forms and that's the only (?) reason why they cannot be used with traits.
Assume for a second that non-references have their own syntax -
(╯°□°)╯︵ &
- then we could likely writeand coherence checker would know that "references are not non-references". And it wouldn't require any new complex machinery - negative bounds, specialization - beyond the existing one.
Conclusion: We should invent a way to write impls for built-in (fixed, not defined by traits), but syntactically inexpressible sets of types.
The text was updated successfully, but these errors were encountered: