Skip to content
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

Use case: const bitflags #47

Closed
joshtriplett opened this issue Jul 26, 2020 · 3 comments
Closed

Use case: const bitflags #47

joshtriplett opened this issue Jul 26, 2020 · 3 comments

Comments

@joshtriplett
Copy link
Member

I'd like to be able to use bitflags as the value of a const:

const MY_FLAGS: SomeFlags = SomeFlags::A | SomeFlags::B;

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?

@jplatte
Copy link

jplatte commented Jul 26, 2020

As written, this requires const fn in traits (rust-lang/rfcs#2632). There is an implementation based on that at bitflags/bitflags#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);

@joshtriplett
Copy link
Member Author

joshtriplett commented Jul 26, 2020

@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.

@RalfJung
Copy link
Member

There's no tracking issue yet because the RFC has not been finalized yet. Closing in favor of rust-lang/rfcs#2632.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants