Open sm-Fifteen opened 4 years ago
Note that the message is technically correct – const
defines an item, and items (other than impl and trait items) don't inherit generic parameters from the thing they're defined in.
Yes, I realize that now. It makes sense why const
was innapropriate in that context (I had the wrong impression on how const
would work inside const fn
s), it's just that the error message wasn't very helpful, and looking it up didn't provide any information about my case.
I tried this code, assuming the result of
size_of::<T>()
would be considered a constant value since it would be known at function monomorphization:This resulted in the following compilation error:
As it turns out, the error message here is incorrect, and the issue can be solved by using
let
instead, something the error message was rather unhelpful with.PLAYGROUND LINK
Meta