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

Incorrect upper bound for size_hint of char::DecodeUtf16 #88762

Closed
steffahn opened this issue Sep 8, 2021 · 0 comments · Fixed by #93347
Closed

Incorrect upper bound for size_hint of char::DecodeUtf16 #88762

steffahn opened this issue Sep 8, 2021 · 0 comments · Fixed by #93347
Labels
A-iterators Area: Iterators C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@steffahn
Copy link
Member

steffahn commented Sep 8, 2021

use std::char::decode_utf16;

fn main() {
    let x = [0xD834, 0x006d];
    let mut d = decode_utf16(x);
    d.next();
    let (_, u) = d.size_hint();
    let c = d.count();
    println!("upper bound: {:?}, actual length {}", u, c);
    assert!(u.unwrap() >= c);
}
   Compiling playground v0.0.1 (/playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.04s
     Running `target/debug/playground`
thread 'main' panicked at 'assertion failed: u.unwrap() >= c', src/main.rs:10:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Standard Output

upper bound: Some(0), actual length 1

(playground)

@rustbot label T-libs, A-iterators

@steffahn steffahn added the C-bug Category: This is a bug. label Sep 8, 2021
@rustbot rustbot added A-iterators Area: Iterators T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 8, 2021
@joshtriplett joshtriplett added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jan 26, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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 bors closed this as completed in 76857fb Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-iterators Area: Iterators C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
3 participants