Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #93491

Closed
wants to merge 26 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
521b1ee
Improve terminology around "after typeck"
pierwill Oct 25, 2021
d671948
Allow eliding GATs in expr position
compiler-errors Jan 15, 2022
3f609b7
Make `span_extend_to_prev_str()` more robust
FabianWolff Jan 15, 2022
104961e
Compute indent never relative to current column
dtolnay Jan 21, 2022
956f1ca
Fix some double indents on exprs containing blocks
dtolnay Jan 21, 2022
03e4001
Bless all pretty printer tests and ui tests
dtolnay Jan 21, 2022
269b5a4
Restore a visual alignment mode for block comments
dtolnay Jan 21, 2022
ecd06e1
Don't suggest inaccessible fields
terrarier2111 Jan 18, 2022
cd4245d
Make char::DecodeUtf16::size_hist more precise
WaffleLapkin Jan 26, 2022
9c8cd1f
Add a test for `char::DecodeUtf16::size_hint`
WaffleLapkin Jan 26, 2022
2c97d10
Fix wrong assumption in `DecodeUtf16::size_hint`
WaffleLapkin Jan 28, 2022
0189a21
Document `SystemTime` platform precision
ChrisDenton Jan 29, 2022
d70b9c0
unix: Use metadata for `DirEntry::file_type` fallback
cuviper Jan 30, 2022
17cd2cd
Fix an edge case in `chat::DecodeUtf16::size_hint`
WaffleLapkin Jan 30, 2022
cde240c
core: Remove some redundant {}s from the sorting code
est31 Jan 30, 2022
78efb07
review the total_cmp documentation
nagisa Jan 28, 2022
99fd534
Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726
matthiaskrgr Jan 30, 2022
1b22492
Rollup merge of #91607 - FabianWolff:issue-91560-const-span, r=jackh726
matthiaskrgr Jan 30, 2022
ef64c52
Rollup merge of #92918 - compiler-errors:gat-expr-lifetime-elision, r…
matthiaskrgr Jan 30, 2022
781ed1e
Rollup merge of #93039 - terrarier2111:fix-field-help, r=nagisa
matthiaskrgr Jan 30, 2022
b3f609b
Rollup merge of #93155 - dtolnay:blockindent, r=nagisa
matthiaskrgr Jan 30, 2022
b984ac0
Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_h…
matthiaskrgr Jan 30, 2022
02b5ff3
Rollup merge of #93403 - nagisa:total-cmp-review, r=joshtriplett
matthiaskrgr Jan 30, 2022
ed50b23
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
matthiaskrgr Jan 30, 2022
6007644
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
matthiaskrgr Jan 30, 2022
060bfcf
Rollup merge of #93485 - est31:remove_curly, r=joshtriplett
matthiaskrgr Jan 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make char::DecodeUtf16::size_hist more precise
New implementation takes into account contents of `self.buf` and rounds
lower bound up instead of down.
WaffleLapkin committed Jan 26, 2022
commit cd4245d318b04c8b44aed7e682c49b0507086d6c
18 changes: 15 additions & 3 deletions library/core/src/char/decode.rs
Original file line number Diff line number Diff line change
@@ -120,9 +120,21 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let (low, high) = self.iter.size_hint();
// we could be entirely valid surrogates (2 elements per
// char), or entirely non-surrogates (1 element per char)
(low / 2, high)

// `self.buf` will never contain the first part of a surrogate,
// so the presence of `buf == Some(...)` always means +1
// on lower and upper bound.
let addition_from_buf = self.buf.is_some() as usize;

// `self.iter` could contain entirely valid surrogates (2 elements per
// char), or entirely non-surrogates (1 element per char).
//
// On odd lower bound, at least one element must stay unpaired
// (with other elements from `self.iter`), so we round up.
let low = low.div_ceil(2) + addition_from_buf;
let high = high.and_then(|h| h.checked_add(addition_from_buf));

(low, high)
}
}