rust-lang / rust-lang/rust

support a way to check bitflags are exhaustive

Open
#149,907 1 comment 0 reactions 1 assignee View on GitHub

@jdonszelmann is already working on this.

Since Dec 12, 2025.

C-enhancement T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Right now you just have to hope that whoever adds a new option to CodegenFnAttrFlags correctly updates all the places where it is relevant, e.g.

https://github.com/rust-lang/rust/blob/c4dc70ee0ad7f811fb32e5bed9cd6c7b37beed4e/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs#L18-L50

cc @jdonszelmann https://github.com/rust-lang/rust/pull/146348

This is quite fragile and I certainly wouldn't have caught this omission in review.

A way to prevent such bugs is by exhaustively matching on all options in such places, e.g.
https://github.com/rust-lang/rust/blob/c4dc70ee0ad7f811fb32e5bed9cd6c7b37beed4e/compiler/rustc_middle/src/ty/context.rs#L632-L638

https://github.com/rust-lang/rust/blob/c4dc70ee0ad7f811fb32e5bed9cd6c7b37beed4e/compiler/rustc_next_trait_solver/src/solve/mod.rs#L72-L81

Imo we should extend our bitflags macro to also emit an enum of all options to enable us to exhaustively match on them in cases where this is likely useful.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.