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

Panic in escape_ascii().len() #99878

Closed
softdevca opened this issue Jul 28, 2022 · 5 comments · Fixed by #99880
Closed

Panic in escape_ascii().len() #99878

softdevca opened this issue Jul 28, 2022 · 5 comments · Fixed by #99880
Assignees
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@softdevca
Copy link

I tried this code:

fn main() {
    "omgwtfbbq".as_bytes().escape_ascii().len();
}

I expected the length of theescape_ascii iterator. Instead, panic:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `None`,
 right: `Some(0)`', /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/iter/traits/exact_size.rs:108:9

Meta

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-unknown-linux-gnu
release: 1.62.1
LLVM version: 14.0.5
My first suspicion would be the size_hint() on the iterator. It also happens in no_std.

Stacktrace:

stack backtrace:
   0: rust_begin_unwind
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:142:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/panicking.rs:181:5
   4: core::iter::traits::exact_size::ExactSizeIterator::len
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/iter/traits/exact_size.rs:108:9
   5: omgwtfbbq::main
             at ./src/main.rs:2:5
   6: core::ops::function::FnOnce::call_once
             at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/ops/function.rs:248:5

@softdevca softdevca added the C-bug Category: This is a bug. label Jul 28, 2022
@compiler-errors compiler-errors self-assigned this Jul 29, 2022
@thomcc thomcc added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Jul 29, 2022
@thomcc
Copy link
Member

thomcc commented Jul 29, 2022

This is pretty unfortunate. This type should not implement ExactSizeIterator, but it has for a few stable versions now :(

See also #77174 (the original tracking issue) and #83130 (the PR that added it)

@the8472 the8472 added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jul 29, 2022
@the8472
Copy link
Member

the8472 commented Jul 29, 2022

Nominating for discussion whether the stabilization should be reverted, the crater run should be expedited and perhaps beta-backported.

@softdevca
Copy link
Author

I would prefer stabilization to be reverted as there is additional book-keeping required to implement ExactSizeIterator.

@softdevca softdevca changed the title Panic in escape_ascii.len() Panic in escape_ascii().len() Jul 29, 2022
@m-ou-se m-ou-se removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Aug 16, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Aug 16, 2022

We discussed this briefly in the libs-api meeting last week. Reverting it seems okay, even though it's technically a breaking change. It seems like nothing relies on it, as they would have gotten panics anyway. The crater run seems to confirm that.

@bors bors closed this as completed in e6f6ad0 Oct 9, 2022
@softdevca
Copy link
Author

Thanks for getting the fix for this merged everybody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
5 participants