4

Github panic early when `TrustedLen` indicates a `length > usize::MAX` by the...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/83726
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

the8472 commented 13 days ago

edited

Changes TrustedLen specializations to immediately panic when size_hint().1 == None.

As far as I can tell this is not a change a minimal change in observable behavior for anything except ZSTs because the fallback path would go through extend_desugared() which tries to reserve(lower_bound) which already is usize::MAX and that would also lead to a panic. Before it might have popped somewhere between zero and a few elements from the iterator before panicking while it now panics immediately.

Overall this should reduce codegen by eliminating the fallback paths.

While looking into the with_capacity() behavior I also noticed that its documentation didn't have a Panics section, so I added that.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK