-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Const Generic value declarations are not required to be used in struct definition #83330
Comments
@jonas-schievink mentions this is intended behavior due to consts not having variance (here on twitter), if this is correct, I'm happy to close the issue. I can't see anything "wrong" this could allow (other than acting as an associated const implicitly, I guess?), it was just a surprise for me. |
I think maybe that's from a very compiler-oriented standpoint, for consts at least having it not be required to be instantiated allows for compile-time configuration, which for me personally is convenient, thinking of mainly linear algebra use-cases or passing compile time flags with structs. If they did have to be used, they would always have to result in some sort of |
Sure, here's an example of a type that uses a const but doesn't store the const in a field: https://github.com/rust-console/voladdress/blob/main/src/volblock.rs |
Awesome, thanks for the clarification! Closing as this is intended behavior. |
I tried this code:
Playground link
I expected to see this happen:
For the following definition:
I expect a compiler error, due to the unused const-generic argument
Instead, this happened:
No error was emitted
Meta
This occurs in the current beta and nightly:
I'm not sure if const generic arguments are required to be used, but I could see this as an "odd" way to tag extra parameters on without them being bound to the actual impls.
The text was updated successfully, but these errors were encountered: