You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:5:13
|
5 | impl <const N: usize> Collatz<{Some(N)}> {
| ^ unconstrained const parameter
However, when using normal generics in the places of the const generics, wrapping the T in an Option and sticking that into the Collatz struct does work:
Is it intended that const generic dont mimmic this behaviour?
This is probably a decision that has to be made (although if it is disallowed, then we'd want a better error message). However, at present, this is a implementation limitation: we really only properly support const generics of the form Foo<N> at the moment (cc ##60471).
which doesn't really make a lot of sense (we have to guarantee that the projection maps each value of T to a unique type).
While Some(N) is injective, finding an intuitive subset of expressions for which this is the case is hard and imo not actually desirable rn.
Not quite sure what's the best error message though 🤔
probably something like
error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates
--> src/main.rs:5:13
|
5 | impl <const N: usize> Collatz<{Some(N)}> {
| ^ unconstrained const parameter
note: const parameters can be constrained by using them in a trivial expression
That's a good point @lcnr. I think adding a note explaining the problem would be the best solution, though the tricky part is working out how to explain it concisely (rather than just stating what the problem is).
Activity
varkor commentedon Jan 20, 2020
This is probably a decision that has to be made (although if it is disallowed, then we'd want a better error message). However, at present, this is a implementation limitation: we really only properly support const generics of the form
Foo<N>at the moment (cc ##60471).lcnr commentedon Aug 11, 2020
Considering that anon consts are mostly just projections, wouldn't this be similar to
which doesn't really make a lot of sense (we have to guarantee that the projection maps each value of
Tto a unique type).While
Some(N)is injective, finding an intuitive subset of expressions for which this is the case is hard and imo not actually desirable rn.Not quite sure what's the best error message though 🤔
probably something like
varkor commentedon Aug 12, 2020
That's a good point @lcnr. I think adding a note explaining the problem would be the best solution, though the tricky part is working out how to explain it concisely (rather than just stating what the problem is).
Rollup merge of rust-lang#76401 - JulianKnodt:i68366, r=lcnr