Rollup merge of #81742 - sdroege:exact-size-iterator-correctness, r=kennytm

Add a note about the correctness and the effect on unsafe code to the `ExactSizeIterator` docs

As it is a safe trait it does not provide any guarantee that the
returned length is correct and as such unsafe code must not rely on it.

That's why `TrustedLen` exists.

Fixes https://github.com/rust-lang/rust/issues/81739
This commit is contained in:
Guillaume Gomez 2021-02-07 14:45:51 +01:00 committed by GitHub
commit f706216251
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,6 +13,12 @@
/// implement it. However, you may be able to provide a more performant /// implement it. However, you may be able to provide a more performant
/// implementation than the default, so overriding it in this case makes sense. /// implementation than the default, so overriding it in this case makes sense.
/// ///
/// Note that this trait is a safe trait and as such does *not* and *cannot*
/// guarantee that the returned length is correct. This means that `unsafe`
/// code **must not** rely on the correctness of [`Iterator::size_hint`]. The
/// unstable and unsafe [`TrustedLen`](super::marker::TrustedLen) trait gives
/// this additional guarantee.
///
/// [`len`]: ExactSizeIterator::len /// [`len`]: ExactSizeIterator::len
/// ///
/// # Examples /// # Examples