Closed joshtriplett closed 4 years ago
As written, this requires const fn
in traits (https://github.com/rust-lang/rfcs/pull/2632). There is an implementation based on that at https://github.com/bitflags/bitflags/pull/217.
As a workaround, this could be done on stable today with const
inherent methods instead of operators:
const MY_FLAGS: SomeFlags = SomeFlags::A.or(SomeFlags::B);
@jplatte .or
looks reasonable to me; thanks! I'll inquire about that on bitflags.
In the meantime, if there's already an issue tracking const handling in traits, feel free to close this in favor of such an issue. Might be worth noting this as a use case in the skill-tree graph, though.
There's no tracking issue yet because the RFC has not been finalized yet. Closing in favor of https://github.com/rust-lang/rfcs/pull/2632.
I'd like to be able to use bitflags as the value of a
const
:This produces an error saying that
calls in constants are limited to constant functions, tuple structs and tuple variants
.What would be the blockers for making bitflags operations work as the value of a
const
?