@@ -165,6 +165,7 @@ use core::ops::{
165
165
} ;
166
166
use core:: pin:: Pin ;
167
167
use core:: ptr:: { self , addr_of_mut, NonNull , Unique } ;
168
+ use core:: slice;
168
169
use core:: task:: { Context , Poll } ;
169
170
170
171
#[ cfg( not( no_global_oom_handling) ) ]
@@ -177,6 +178,7 @@ use crate::raw_vec::RawVec;
177
178
use crate :: str:: from_boxed_utf8_unchecked;
178
179
#[ cfg( not( no_global_oom_handling) ) ]
179
180
use crate :: string:: String ;
181
+ use crate :: vec;
180
182
#[ cfg( not( no_global_oom_handling) ) ]
181
183
use crate :: vec:: Vec ;
182
184
@@ -2080,6 +2082,47 @@ impl<I> FromIterator<I> for Box<[I]> {
2080
2082
}
2081
2083
}
2082
2084
2085
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2086
+ impl < I , const N : usize , A : Allocator > !Iterator for Box < [ I ; N ] , A > { }
2087
+
2088
+ /// `Box` is fundamental, so coherence needs help understanding these impls are okay.
2089
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2090
+ impl < ' a , const N : usize , I , A : Allocator > !Iterator for & ' a Box < [ I ; N ] , A > { }
2091
+
2092
+ /// `Box` is fundamental, so coherence needs help understanding these impls are okay.
2093
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2094
+ impl < ' a , const N : usize , I , A : Allocator > !Iterator for & ' a mut Box < [ I ; N ] , A > { }
2095
+
2096
+ // Note: the `#[rustc_skip_during_method_dispatch(boxed_slice)]` on `trait IntoIterator`
2097
+ // hides this implementation from explicit `.into_iter()` calls on editions < 2024,
2098
+ // so those calls will still resolve to the slice implementation, by reference.
2099
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2100
+ impl < I , const N : usize , A : Allocator > IntoIterator for Box < [ I ; N ] , A > {
2101
+ type IntoIter = vec:: IntoIter < I , A > ;
2102
+ type Item = I ;
2103
+ fn into_iter ( self ) -> vec:: IntoIter < I , A > {
2104
+ ( self as Box < [ I ] , A > ) . into_vec ( ) . into_iter ( )
2105
+ }
2106
+ }
2107
+
2108
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2109
+ impl < ' a , I , const N : usize , A : Allocator > IntoIterator for & ' a Box < [ I ; N ] , A > {
2110
+ type IntoIter = slice:: Iter < ' a , I > ;
2111
+ type Item = & ' a I ;
2112
+ fn into_iter ( self ) -> slice:: Iter < ' a , I > {
2113
+ self . iter ( )
2114
+ }
2115
+ }
2116
+
2117
+ #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION" ) ]
2118
+ impl < ' a , I , const N : usize , A : Allocator > IntoIterator for & ' a mut Box < [ I ; N ] , A > {
2119
+ type IntoIter = slice:: IterMut < ' a , I > ;
2120
+ type Item = & ' a mut I ;
2121
+ fn into_iter ( self ) -> slice:: IterMut < ' a , I > {
2122
+ self . iter_mut ( )
2123
+ }
2124
+ }
2125
+
2083
2126
#[ cfg( not( no_global_oom_handling) ) ]
2084
2127
#[ stable( feature = "box_slice_clone" , since = "1.3.0" ) ]
2085
2128
impl < T : Clone , A : Allocator + Clone > Clone for Box < [ T ] , A > {
0 commit comments