Skip to content

ByteMask: inclusive bit-range edits change nothing for an empty range - #211

Open
imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:fix/byte-mask-empty-inclusive-range
Open

imlvts wants to merge 1 commit into
Adam-Vandervorst:masterfrom
imlvts:fix/byte-mask-empty-inclusive-range

Conversation

@imlvts

@imlvts imlvts commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

set_/clear_/toggle_inclusive_bit_range read only the range's start() and end(). A RangeInclusive iterated to its end is empty, but both bounds then read end, so the methods acted on that bit; ByteMask::from of the same range (through RangeBounds) is correctly empty. An ordinary empty a..=b with a > b tripped BlockRange's debug_assert, though release did the right thing.

Both are caught by RangeInclusive::is_empty, which is not const, so the three methods are no longer const fns. Nothing in the crate (or MORK) calls them in a const context.

set_/clear_/toggle_inclusive_bit_range with `a..=b`, `a > b` (an ordinary
empty range, which ByteMask::from_range treats as empty) tripped BlockRange's
debug_assert in debug builds, and failed const evaluation in a const context;
release did the right thing.  They now check the bounds and do nothing.

RangeInclusive::is_empty isn't const, so emptiness is read from the bounds,
which keeps the methods const.  A range iterated to its end can't be told from
`end..=end` that way (its bounds then read `end..=end`), so the methods
document that they read only the bounds and take ranges that haven't been
iterated.
@imlvts
imlvts force-pushed the fix/byte-mask-empty-inclusive-range branch from e7a566d to e84c156 Compare November 30, 2026 21:14
@Adam-Vandervorst

Copy link
Copy Markdown
Owner

What do we actually use block range for? Do we need it?

@imlvts

imlvts commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator Author

We actually don't use it anywhere. _inclusive_bit_range only shows in tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants