From ce3b6f505ed8c0a285461f4f9b729b62e7703354 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Sun, 12 Jun 2022 00:55:09 +0200 Subject: [PATCH] Expose iter::ByRefSized as unstable feature and use it --- library/alloc/src/collections/vec_deque/spec_extend.rs | 2 +- library/alloc/src/lib.rs | 1 + library/core/src/iter/adapters/by_ref_sized.rs | 6 +++++- library/core/src/iter/adapters/mod.rs | 3 ++- library/core/src/iter/mod.rs | 4 +++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/spec_extend.rs b/library/alloc/src/collections/vec_deque/spec_extend.rs index cea2b7543ce..97ff8b76524 100644 --- a/library/alloc/src/collections/vec_deque/spec_extend.rs +++ b/library/alloc/src/collections/vec_deque/spec_extend.rs @@ -1,6 +1,6 @@ use crate::alloc::Allocator; use crate::vec; -use core::iter::TrustedLen; +use core::iter::{ByRefSized, TrustedLen}; use core::slice; use super::VecDeque; diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index baa1106a0dd..c08caa7b93e 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -143,6 +143,7 @@ #![feature(unchecked_math)] #![feature(unicode_internals)] #![feature(unsize)] +#![feature(std_internals)] // // Language features: #![feature(allocator_internals)] diff --git a/library/core/src/iter/adapters/by_ref_sized.rs b/library/core/src/iter/adapters/by_ref_sized.rs index bf2e3e182e2..cc1e8e8a27f 100644 --- a/library/core/src/iter/adapters/by_ref_sized.rs +++ b/library/core/src/iter/adapters/by_ref_sized.rs @@ -4,8 +4,11 @@ use crate::ops::Try; /// /// Ideally this will no longer be required, eventually, but as can be seen in /// the benchmarks (as of Feb 2022 at least) `by_ref` can have performance cost. -pub(crate) struct ByRefSized<'a, I>(pub &'a mut I); +#[unstable(feature = "std_internals", issue = "none")] +#[derive(Debug)] +pub struct ByRefSized<'a, I>(pub &'a mut I); +#[unstable(feature = "std_internals", issue = "none")] impl Iterator for ByRefSized<'_, I> { type Item = I::Item; @@ -47,6 +50,7 @@ impl Iterator for ByRefSized<'_, I> { } } +#[unstable(feature = "std_internals", issue = "none")] impl DoubleEndedIterator for ByRefSized<'_, I> { #[inline] fn next_back(&mut self) -> Option { diff --git a/library/core/src/iter/adapters/mod.rs b/library/core/src/iter/adapters/mod.rs index 4500b44b7e9..916a26e2424 100644 --- a/library/core/src/iter/adapters/mod.rs +++ b/library/core/src/iter/adapters/mod.rs @@ -32,7 +32,8 @@ pub use self::{ scan::Scan, skip::Skip, skip_while::SkipWhile, take::Take, take_while::TakeWhile, zip::Zip, }; -pub(crate) use self::by_ref_sized::ByRefSized; +#[unstable(feature = "std_internals", issue = "none")] +pub use self::by_ref_sized::ByRefSized; #[stable(feature = "iter_cloned", since = "1.1.0")] pub use self::cloned::Cloned; diff --git a/library/core/src/iter/mod.rs b/library/core/src/iter/mod.rs index 15362d2330a..d5c6aed5b6c 100644 --- a/library/core/src/iter/mod.rs +++ b/library/core/src/iter/mod.rs @@ -398,6 +398,8 @@ pub use self::traits::{ #[stable(feature = "iter_zip", since = "1.59.0")] pub use self::adapters::zip; +#[unstable(feature = "std_internals", issue = "none")] +pub use self::adapters::ByRefSized; #[stable(feature = "iter_cloned", since = "1.1.0")] pub use self::adapters::Cloned; #[stable(feature = "iter_copied", since = "1.36.0")] @@ -422,7 +424,7 @@ pub use self::adapters::{ #[unstable(feature = "iter_intersperse", reason = "recently added", issue = "79524")] pub use self::adapters::{Intersperse, IntersperseWith}; -pub(crate) use self::adapters::{try_process, ByRefSized}; +pub(crate) use self::adapters::try_process; mod adapters; mod range;