New undocumented `panic!` in Rust 1.92.0?

I posted this message in the https://internals.rust-lang.org forum, could somebody confirm (or not) the problem? Rust 1.92.0 pre-release testing - #6 by tdelmas - announcements - Rust Internals

Rust Release Notes

It seems they added a panic! for last without documenting it, or am I missing it? (count does document the panic! in Iterator: Iterator in std::iter - Rust)

This program runs forever on stable 1.91.1 and panics on nightly; nightly docs don't mention the panic.

1 Like

That program indeed panics on stable 1.92 (it got out just now). And the stable docs don't mention the panic.

As it seems confirmed, I have (re)open Document `panic!` for Iterator::last (Repeat) · Issue #149707 · rust-lang/rust · GitHub

I must say that i don't particularly like the fact that certain implementations of Iterator panic and thus may cause unpredictable behavior for trait bounded generic types. Maybe this particular edge case of Repeat shows that certain iterator features should be outsourced into separate traits which are only implemented for types where such a method makes sense.

4 Likes

Well, with that panic! now in stable rust, for me it must be documented in two places :

  • In the Iterator trait to say that last may panic (for Iterator without a last element?)
  • In the Repeat implementation, as the panic! is systematic when calling last

Also, I don't understand why they decided to panic! when Iterator::last return an option that can be None (and the documentation isn't clean why/when it should/may return None)

2 Likes

I think the answer is there: Tracking issue for release notes of #146410: Iterator repeat: no infinite loop for `last` and `count` · Issue #146660 · rust-lang/rust · GitHub

Just for the fun of it... Small change, huge difference, 'cause other Iterator implementor.

1 Like

I feel that this does request opening a separate issue... @conqp do you want to do it?