Skip to content

Fix a bug in ChunkedBitSet::subtract#155381

Open
nnethercote wants to merge 2 commits intorust-lang:mainfrom
nnethercote:fix-ChunkedBitSet-subtract
Open

Fix a bug in ChunkedBitSet::subtract#155381
nnethercote wants to merge 2 commits intorust-lang:mainfrom
nnethercote:fix-ChunkedBitSet-subtract

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

@nnethercote nnethercote commented Apr 16, 2026

An operator precedence bug means an incorrect mask is used in ChunkedBitSet::subtract. Details in individual commits.

r? @dingxiangfei2009

It results in `b64` having many fewer bits set than it should.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
It does a masking operation but the mask is computed incorrectly due to
operator precedence. The mask is of the form `1 << N - 1` but it
should be `(1 << N) - 1` because `-` binds tighter than `1 << N`.

This commit fixes the problem, not by adjusting the precedence, but by
instead using the existing `clear_excess_bits_in_final_word`, which is
consistent with other similar operations.

LLM disclosure: this bug was identified by Claude Code. I did everything
else.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants