Skip to content

Commit

Permalink
Rollup merge of rust-lang#81599 - sdroege:fuse-trusted-len, r=m-ou-se
Browse files Browse the repository at this point in the history
Implement `TrustedLen` for `Fuse<I: TrustedLen>`

This looks like it was simply forgotten.
  • Loading branch information
JohnTitor authored Feb 2, 2021
2 parents a06716b + 12b605a commit 085d885
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion library/core/src/iter/adapters/fuse.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::intrinsics;
use crate::iter::adapters::{zip::try_get_unchecked, InPlaceIterable, SourceIter};
use crate::iter::{DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedRandomAccess};
use crate::iter::{
DoubleEndedIterator, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccess,
};
use crate::ops::Try;

/// An iterator that yields `None` forever after the underlying iterator
Expand Down Expand Up @@ -182,8 +184,19 @@ where
}
}

#[unstable(feature = "trusted_len", issue = "37572")]
// SAFETY: `TrustedLen` requires that an accurate length is reported via `size_hint()`. As `Fuse`
// is just forwarding this to the wrapped iterator `I` this property is preserved and it is safe to
// implement `TrustedLen` here.
unsafe impl<I> TrustedLen for Fuse<I> where I: TrustedLen {}

#[doc(hidden)]
#[unstable(feature = "trusted_random_access", issue = "none")]
// SAFETY: `TrustedRandomAccess` requires that `size_hint()` must be exact and cheap to call, and
// `Iterator::__iterator_get_unchecked()` must be implemented accordingly.
//
// This is safe to implement as `Fuse` is just forwarding these to the wrapped iterator `I`, which
// preserves these properties.
unsafe impl<I> TrustedRandomAccess for Fuse<I>
where
I: TrustedRandomAccess,
Expand Down

0 comments on commit 085d885

Please sign in to comment.