Make char::DecodeUtf16::size_hist more precise#93347
Merged
bors merged 4 commits intorust-lang:masterfrom Jan 31, 2022
Merged
Conversation
New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down.
Contributor
|
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
the8472
reviewed
Jan 27, 2022
dtolnay
requested changes
Jan 28, 2022
library/core/src/char/decode.rs
Outdated
| // char), or entirely non-surrogates (1 element per char) | ||
| (low / 2, high) | ||
|
|
||
| // `self.buf` will never contain the first part of a surrogate, |
Member
There was a problem hiding this comment.
Why? It doesn't seem to me like that's the case.
For example the following would fail the test below.
check(&[0xD800, 0xD800, 0xDC00]);thread 'char::test_decode_utf16_size_hint' panicked at 'lower = 2, upper = Some(2)', library/core/tests/char.rs:320:13
Member
Author
There was a problem hiding this comment.
It was a wrong assumption from the original PR that I haven't checked 😅
I pushed a fix that checks the contents of the buf.
a40122c to
2c97d10
Compare
`self.buf` can contain a surrogate, but only a leading one.
This comment has been minimized.
This comment has been minimized.
dtolnay
requested changes
Jan 28, 2022
Member
dtolnay
left a comment
There was a problem hiding this comment.
check(&[0xD800, 0xD800, 0x0]) fails your test.
thread 'char::test_decode_utf16_size_hint' panicked at 'lower = 1, count = 2, upper = Some(1)', library/core/tests/char.rs:320:13There are cases, when data in the buf might or might not be an error.
Member
Author
|
@dtolnay I fixed this edge case too. I wander if I still missed something 😄 |
Member
|
@bors r+ |
Collaborator
|
📌 Commit 17cd2cd has been approved by |
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Jan 30, 2022
…16_size_hint, r=dtolnay Make `char::DecodeUtf16::size_hist` more precise New implementation takes into account contents of `self.buf` and rounds lower bound up instead of down. Fixes rust-lang#88762 Revival of rust-lang#88763
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 31, 2022
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#90277 (Improve terminology around "after typeck") - rust-lang#92918 (Allow eliding GATs in expression position) - rust-lang#93039 (Don't suggest inaccessible fields) - rust-lang#93155 (Switch pretty printer to block-based indentation) - rust-lang#93214 (Respect doc(hidden) when suggesting available fields) - rust-lang#93347 (Make `char::DecodeUtf16::size_hist` more precise) - rust-lang#93392 (Clarify documentation on char::MAX) - rust-lang#93444 (Fix some CSS warnings and errors from VS Code) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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.
New implementation takes into account contents of
self.bufand rounds lower bound up instead of down.Fixes #88762
Revival of #88763