Repository navigation
Conversation
When an interval set contains ranges on either side of the surrogate
codepoints, such as `..=\u{D7FF}` and `\u{E000}..`, negation computed
the gap between them with `increment`/`decrement`, which skip over the
surrogates. That yields `lower = \u{E000}` and `upper = \u{D7FF}`, and
`Interval::create` then swaps the inverted bounds into the range
`\u{D7FF}..=\u{E000}`. So both codepoints ended up matching their own
negation:
Regex::new(r"^[^\x{D7FF}\x{E000}]$").unwrap().is_match("\u{D7FF}")
Such ranges are never merged by `canonicalize`, since `is_contiguous`
compares the integer values and `0xD7FF + 1 != 0xE000`. So handle the
empty gap in `negate` instead and skip it.
Fixes rust-lang#1397
This branch has not been deployed
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.
Fixes #1397.
IntervalSet::negatecomputes the gap between two adjacent canonical ranges withincrement()/decrement(). For ranges on either side of the surrogate codepoints, such as..=\u{D7FF}and\u{E000}.., both steps jump over the surrogates, which yieldslower = \u{E000}andupper = \u{D7FF}.Interval::createthen swaps the inverted bounds and produces\u{D7FF}..=\u{E000}, so both codepoints end up matching their own negation:canonicalizenever merges these two ranges, sinceis_contiguouscompares the integer values and0xD7FF + 1 != 0xE000. So the fix handles the empty gap innegateitself: whenlower > upperthere is nothing between the ranges and no range is pushed. Byte classes are unaffected, asu8has no such gap.Tests:
hir/mod.rsfor the three shapes: the two codepoints alone, the full set whose negation must be empty, and a mixed set,testdata/regression.tomlforU+D7FF,U+E000and the neighbouringU+D7FE.I left the CHANGELOG untouched; happy to add an entry if you prefer that in the PR.
Disclosure: assisted by GitHub Copilot and Claude (including this description). I reviewed and tested the change myself.