Skip to content

Commit

Permalink
move AsIntoIter helper trait and mark it as unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Mar 21, 2022
1 parent 47a7a07 commit 79b43b3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion library/alloc/src/collections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ unsafe impl<T> SourceIter for IntoIter<T> {
#[doc(hidden)]
unsafe impl<I> InPlaceIterable for IntoIter<I> {}

impl<I> AsIntoIter for IntoIter<I> {
unsafe impl<I> AsIntoIter for IntoIter<I> {
type Item = I;

fn as_into_iter(&mut self) -> &mut vec::IntoIter<Self::Item> {
Expand Down
9 changes: 8 additions & 1 deletion library/alloc/src/vec/in_place_collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::iter::{InPlaceIterable, SourceIter, TrustedRandomAccessNoCoerce};
use core::mem::{self, ManuallyDrop};
use core::ptr::{self};

use super::{AsIntoIter, InPlaceDrop, SpecFromIter, SpecFromIterNested, Vec};
use super::{InPlaceDrop, SpecFromIter, SpecFromIterNested, Vec};

/// Specialization marker for collecting an iterator pipeline into a Vec while reusing the
/// source allocation, i.e. executing the pipeline in place.
Expand Down Expand Up @@ -154,3 +154,10 @@ where
len
}
}

// internal helper trait for in-place iteration specialization.
#[rustc_specialization_trait]
pub(crate) unsafe trait AsIntoIter {
type Item;
fn as_into_iter(&mut self) -> &mut super::IntoIter<Self::Item>;
}
12 changes: 4 additions & 8 deletions library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[cfg(not(no_global_oom_handling))]
use super::AsIntoIter;
use crate::alloc::{Allocator, Global};
use crate::raw_vec::RawVec;
use core::fmt;
Expand Down Expand Up @@ -338,14 +340,8 @@ unsafe impl<T, A: Allocator> SourceIter for IntoIter<T, A> {
}
}

// internal helper trait for in-place iteration specialization.
#[rustc_specialization_trait]
pub(crate) trait AsIntoIter {
type Item;
fn as_into_iter(&mut self) -> &mut IntoIter<Self::Item>;
}

impl<T> AsIntoIter for IntoIter<T> {
#[cfg(not(no_global_oom_handling))]
unsafe impl<T> AsIntoIter for IntoIter<T> {
type Item = T;

fn as_into_iter(&mut self) -> &mut IntoIter<Self::Item> {
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod drain;
mod cow;

#[cfg(not(no_global_oom_handling))]
pub(crate) use self::into_iter::AsIntoIter;
pub(crate) use self::in_place_collect::AsIntoIter;
#[stable(feature = "rust1", since = "1.0.0")]
pub use self::into_iter::IntoIter;

Expand Down

0 comments on commit 79b43b3

Please sign in to comment.