Skip to content

Commit f31acaa

Browse files
committed
IntoIterator for Box<[T]>
1 parent 130ff8c commit f31acaa

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/rustc_ast/src/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a, T> IntoIterator for &'a P<[T]> {
186186
type Item = &'a T;
187187
type IntoIter = slice::Iter<'a, T>;
188188
fn into_iter(self) -> Self::IntoIter {
189-
self.ptr.into_iter()
189+
self.ptr.iter()
190190
}
191191
}
192192

library/alloc/src/boxed.rs

+38
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ use core::ops::{
163163
};
164164
use core::pin::Pin;
165165
use core::ptr::{self, NonNull, Unique};
166+
use core::slice;
166167
use core::task::{Context, Poll};
167168

168169
#[cfg(not(no_global_oom_handling))]
@@ -175,6 +176,7 @@ use crate::raw_vec::RawVec;
175176
use crate::str::from_boxed_utf8_unchecked;
176177
#[cfg(not(no_global_oom_handling))]
177178
use crate::string::String;
179+
use crate::vec;
178180
#[cfg(not(no_global_oom_handling))]
179181
use crate::vec::Vec;
180182

@@ -2036,6 +2038,42 @@ impl<I> FromIterator<I> for Box<[I]> {
20362038
}
20372039
}
20382040

2041+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2042+
impl<I, A: Allocator> !Iterator for Box<[I], A> {}
2043+
2044+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2045+
impl<I, A: Allocator> IntoIterator for Box<[I], A> {
2046+
type IntoIter = vec::IntoIter<I, A>;
2047+
type Item = I;
2048+
fn into_iter(self) -> vec::IntoIter<I, A> {
2049+
self.into_vec().into_iter()
2050+
}
2051+
}
2052+
2053+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2054+
impl<'a, I, A: Allocator> !Iterator for &'a Box<[I], A> {}
2055+
2056+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2057+
impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
2058+
type IntoIter = slice::Iter<'a, I>;
2059+
type Item = &'a I;
2060+
fn into_iter(self) -> slice::Iter<'a, I> {
2061+
self.iter()
2062+
}
2063+
}
2064+
2065+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2066+
impl<'a, I, A: Allocator> !Iterator for &'a mut Box<[I], A> {}
2067+
2068+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2069+
impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
2070+
type IntoIter = slice::IterMut<'a, I>;
2071+
type Item = &'a mut I;
2072+
fn into_iter(self) -> slice::IterMut<'a, I> {
2073+
self.iter_mut()
2074+
}
2075+
}
2076+
20392077
#[cfg(not(no_global_oom_handling))]
20402078
#[stable(feature = "box_slice_clone", since = "1.3.0")]
20412079
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> {

library/core/src/slice/iter.rs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ use crate::ptr::{self, invalid, invalid_mut, NonNull};
1717

1818
use super::{from_raw_parts, from_raw_parts_mut};
1919

20+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
21+
impl<T> !Iterator for [T] {}
22+
2023
#[stable(feature = "rust1", since = "1.0.0")]
2124
impl<'a, T> IntoIterator for &'a [T] {
2225
type Item = &'a T;

0 commit comments

Comments
 (0)