Skip to content

Commit a9a6e8b

Browse files
committed
IntoIterator for Box<[T]>
1 parent 6ec953c commit a9a6e8b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/rustc_ast/src/ptr.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ use core::ops::{
165165
};
166166
use core::pin::Pin;
167167
use core::ptr::{self, addr_of_mut, NonNull, Unique};
168+
use core::slice;
168169
use core::task::{Context, Poll};
169170

170171
#[cfg(not(no_global_oom_handling))]
@@ -177,6 +178,7 @@ use crate::raw_vec::RawVec;
177178
use crate::str::from_boxed_utf8_unchecked;
178179
#[cfg(not(no_global_oom_handling))]
179180
use crate::string::String;
181+
use crate::vec;
180182
#[cfg(not(no_global_oom_handling))]
181183
use crate::vec::Vec;
182184

@@ -2073,6 +2075,42 @@ impl<I> FromIterator<I> for Box<[I]> {
20732075
}
20742076
}
20752077

2078+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2079+
impl<I, A: Allocator> !Iterator for Box<[I], A> {}
2080+
2081+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2082+
impl<I, A: Allocator> IntoIterator for Box<[I], A> {
2083+
type IntoIter = vec::IntoIter<I, A>;
2084+
type Item = I;
2085+
fn into_iter(self) -> vec::IntoIter<I, A> {
2086+
self.into_vec().into_iter()
2087+
}
2088+
}
2089+
2090+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2091+
impl<'a, I, A: Allocator> !Iterator for &'a Box<[I], A> {}
2092+
2093+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2094+
impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
2095+
type IntoIter = slice::Iter<'a, I>;
2096+
type Item = &'a I;
2097+
fn into_iter(self) -> slice::Iter<'a, I> {
2098+
self.iter()
2099+
}
2100+
}
2101+
2102+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2103+
impl<'a, I, A: Allocator> !Iterator for &'a mut Box<[I], A> {}
2104+
2105+
#[stable(feature = "boxed_slice_into_iter", since = "CURRENT_RUSTC_VERSION")]
2106+
impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
2107+
type IntoIter = slice::IterMut<'a, I>;
2108+
type Item = &'a mut I;
2109+
fn into_iter(self) -> slice::IterMut<'a, I> {
2110+
self.iter_mut()
2111+
}
2112+
}
2113+
20762114
#[cfg(not(no_global_oom_handling))]
20772115
#[stable(feature = "box_slice_clone", since = "1.3.0")]
20782116
impl<T: Clone, A: Allocator + Clone> Clone for Box<[T], A> {

library/core/src/slice/iter.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ use crate::ptr::{self, without_provenance, without_provenance_mut, NonNull};
1616

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

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

0 commit comments

Comments
 (0)