From 99893346e85de78cb9cb021f831a2fe0b7dd1470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 1 Feb 2021 09:44:10 +0200 Subject: [PATCH] Add SAFETY comment for the `TrustedRandomAccess` impl of `iter::Fuse` --- library/core/src/iter/adapters/fuse.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/iter/adapters/fuse.rs b/library/core/src/iter/adapters/fuse.rs index ae0740653159..fc5fbd60b64d 100644 --- a/library/core/src/iter/adapters/fuse.rs +++ b/library/core/src/iter/adapters/fuse.rs @@ -184,6 +184,11 @@ where #[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 TrustedRandomAccess for Fuse where I: TrustedRandomAccess,