DepKind cleanups - #160406
Open
nnethercote wants to merge 3 commits into
Open
Conversation
This commit changes `DEP_KIND_NUM_VARIANTS` so it's an associated const (renamed as `DepKind::NUM_VARIANTS`) obtained via `std::mem::variant_count`, removing the paranoid consecutiveness check. The commit also replaces multiple `DepKind::MAX as usize + 1` occurrences with `DepKind::NUM_VARIANTS`.
It contains pre-stringified versions of all the `DepKind` variants. But
we can just stringify on demand using `format!("{:?}")`.
Collaborator
|
|
cjgillot
reviewed
Aug 3, 2026
| /// pack information into the unused bits. u16 matches the `repr(u16)` on `DepKind`. | ||
| pub(crate) const MAX: u16 = { | ||
| let max = Self::NUM_VARIANTS - 1; | ||
| assert!(max < u16::MAX as usize); |
Contributor
There was a problem hiding this comment.
Why do we bother asserting? If the subtraction underflows, the constant won't compile, will it?
Contributor
Author
There was a problem hiding this comment.
NUM_VARIANTS is a usize. The intent here isn't to detect underflow, but to ensure there aren't more than 64K variants.
Member
There was a problem hiding this comment.
And while the variant count is presumably capped by #[repr(u16)] on the enum, this assertion has the benefit of making max as u16 obviously correct.
nnethercote
force-pushed
the
DepKind-cleanups
branch
from
August 3, 2026 02:34
1d9c8fd to
a707cbf
Compare
Member
|
Looks good, thanks. r=me when PR CI is green. |
Member
|
@bors r+ |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 3, 2026
…lathar `DepKind` cleanups Details in individual commits. r? Zalathar
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 3, 2026
…lathar `DepKind` cleanups Details in individual commits. r? Zalathar
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 3, 2026
…uwer Rollup of 6 pull requests Successful merges: - #159844 (Subtree cg_gcc sync (2026-07-24)) - #160406 (`DepKind` cleanups) - #159303 (Fix ICE for direct inline const generic defaults) - #160314 (fix borrowck ICE for consts with fn pointer type) - #160322 (ElaborateBoxDeref: remove unnecessary projection) - #160384 (Add PR body notes for Cargo lock file maintenance)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 3, 2026
…lathar `DepKind` cleanups Details in individual commits. r? Zalathar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details in individual commits.
r? Zalathar