145145//! to `into_iter()` for boxed slices will defer to the slice implementation on editions before
146146//! 2024:
147147//!
148- #![ cfg_attr( bootstrap, doc = "```rust,edition2021,ignore" ) ]
149- #![ cfg_attr( not( bootstrap) , doc = "```rust,edition2021" ) ]
148+ //! ```rust,edition2021
150149//! // Rust 2015, 2018, and 2021:
151150//!
152151//! # #![allow(boxed_slice_into_iter)] // override our `deny(warnings)`
189188use core:: any:: Any ;
190189use core:: async_iter:: AsyncIterator ;
191190use core:: borrow;
191+ #[ cfg( not( no_global_oom_handling) ) ]
192+ use core:: clone:: CloneToUninit ;
192193use core:: cmp:: Ordering ;
193194use core:: error:: Error ;
194195use core:: fmt;
@@ -208,7 +209,7 @@ use core::slice;
208209use core:: task:: { Context , Poll } ;
209210
210211#[ cfg( not( no_global_oom_handling) ) ]
211- use crate :: alloc:: { handle_alloc_error, WriteCloneIntoRaw } ;
212+ use crate :: alloc:: handle_alloc_error;
212213use crate :: alloc:: { AllocError , Allocator , Global , Layout } ;
213214#[ cfg( not( no_global_oom_handling) ) ]
214215use crate :: borrow:: Cow ;
@@ -1212,6 +1213,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12121213 /// let static_ref: &'static mut usize = Box::leak(x);
12131214 /// *static_ref += 1;
12141215 /// assert_eq!(*static_ref, 42);
1216+ /// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
1217+ /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
1218+ /// # drop(unsafe { Box::from_raw(static_ref) });
12151219 /// ```
12161220 ///
12171221 /// Unsized data:
@@ -1221,6 +1225,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12211225 /// let static_ref = Box::leak(x);
12221226 /// static_ref[0] = 4;
12231227 /// assert_eq!(*static_ref, [4, 2, 3]);
1228+ /// # // FIXME(https://github.com/rust-lang/miri/issues/3670):
1229+ /// # // use -Zmiri-disable-leak-check instead of unleaking in tests meant to leak.
1230+ /// # drop(unsafe { Box::from_raw(static_ref) });
12241231 /// ```
12251232 #[ stable( feature = "box_leak" , since = "1.26.0" ) ]
12261233 #[ inline]
@@ -1347,7 +1354,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
13471354 // Pre-allocate memory to allow writing the cloned value directly.
13481355 let mut boxed = Self :: new_uninit_in ( self . 1 . clone ( ) ) ;
13491356 unsafe {
1350- ( * * self ) . write_clone_into_raw ( boxed. as_mut_ptr ( ) ) ;
1357+ ( * * self ) . clone_to_uninit ( boxed. as_mut_ptr ( ) ) ;
13511358 boxed. assume_init ( )
13521359 }
13531360 }
@@ -2123,23 +2130,23 @@ impl<I> FromIterator<I> for Box<[I]> {
21232130
21242131/// This implementation is required to make sure that the `Box<[I]>: IntoIterator`
21252132/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2126- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2133+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21272134impl < I , A : Allocator > !Iterator for Box < [ I ] , A > { }
21282135
21292136/// This implementation is required to make sure that the `&Box<[I]>: IntoIterator`
21302137/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2131- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2138+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21322139impl < ' a , I , A : Allocator > !Iterator for & ' a Box < [ I ] , A > { }
21332140
21342141/// This implementation is required to make sure that the `&mut Box<[I]>: IntoIterator`
21352142/// implementation doesn't overlap with `IntoIterator for T where T: Iterator` blanket.
2136- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2143+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21372144impl < ' a , I , A : Allocator > !Iterator for & ' a mut Box < [ I ] , A > { }
21382145
21392146// Note: the `#[rustc_skip_during_method_dispatch(boxed_slice)]` on `trait IntoIterator`
21402147// hides this implementation from explicit `.into_iter()` calls on editions < 2024,
21412148// so those calls will still resolve to the slice implementation, by reference.
2142- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2149+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21432150impl < I , A : Allocator > IntoIterator for Box < [ I ] , A > {
21442151 type IntoIter = vec:: IntoIter < I , A > ;
21452152 type Item = I ;
@@ -2148,7 +2155,7 @@ impl<I, A: Allocator> IntoIterator for Box<[I], A> {
21482155 }
21492156}
21502157
2151- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2158+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21522159impl < ' a , I , A : Allocator > IntoIterator for & ' a Box < [ I ] , A > {
21532160 type IntoIter = slice:: Iter < ' a , I > ;
21542161 type Item = & ' a I ;
@@ -2157,7 +2164,7 @@ impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
21572164 }
21582165}
21592166
2160- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2167+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
21612168impl < ' a , I , A : Allocator > IntoIterator for & ' a mut Box < [ I ] , A > {
21622169 type IntoIter = slice:: IterMut < ' a , I > ;
21632170 type Item = & ' a mut I ;
@@ -2167,47 +2174,47 @@ impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
21672174}
21682175
21692176#[ cfg( not( no_global_oom_handling) ) ]
2170- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2177+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
21712178impl FromIterator < char > for Box < str > {
21722179 fn from_iter < T : IntoIterator < Item = char > > ( iter : T ) -> Self {
21732180 String :: from_iter ( iter) . into_boxed_str ( )
21742181 }
21752182}
21762183
21772184#[ cfg( not( no_global_oom_handling) ) ]
2178- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2185+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
21792186impl < ' a > FromIterator < & ' a char > for Box < str > {
21802187 fn from_iter < T : IntoIterator < Item = & ' a char > > ( iter : T ) -> Self {
21812188 String :: from_iter ( iter) . into_boxed_str ( )
21822189 }
21832190}
21842191
21852192#[ cfg( not( no_global_oom_handling) ) ]
2186- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2193+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
21872194impl < ' a > FromIterator < & ' a str > for Box < str > {
21882195 fn from_iter < T : IntoIterator < Item = & ' a str > > ( iter : T ) -> Self {
21892196 String :: from_iter ( iter) . into_boxed_str ( )
21902197 }
21912198}
21922199
21932200#[ cfg( not( no_global_oom_handling) ) ]
2194- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2201+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
21952202impl FromIterator < String > for Box < str > {
21962203 fn from_iter < T : IntoIterator < Item = String > > ( iter : T ) -> Self {
21972204 String :: from_iter ( iter) . into_boxed_str ( )
21982205 }
21992206}
22002207
22012208#[ cfg( not( no_global_oom_handling) ) ]
2202- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2209+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
22032210impl < A : Allocator > FromIterator < Box < str , A > > for Box < str > {
22042211 fn from_iter < T : IntoIterator < Item = Box < str , A > > > ( iter : T ) -> Self {
22052212 String :: from_iter ( iter) . into_boxed_str ( )
22062213 }
22072214}
22082215
22092216#[ cfg( not( no_global_oom_handling) ) ]
2210- #[ stable( feature = "boxed_str_from_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2217+ #[ stable( feature = "boxed_str_from_iter" , since = "1.80.0 " ) ]
22112218impl < ' a > FromIterator < Cow < ' a , str > > for Box < str > {
22122219 fn from_iter < T : IntoIterator < Item = Cow < ' a , str > > > ( iter : T ) -> Self {
22132220 String :: from_iter ( iter) . into_boxed_str ( )
@@ -2373,7 +2380,7 @@ impl dyn Error + Send {
23732380 let err: Box < dyn Error > = self ;
23742381 <dyn Error >:: downcast ( err) . map_err ( |s| unsafe {
23752382 // Reapply the `Send` marker.
2376- Box :: from_raw ( Box :: into_raw ( s ) as * mut ( dyn Error + Send ) )
2383+ mem :: transmute :: < Box < dyn Error > , Box < dyn Error + Send > > ( s )
23772384 } )
23782385 }
23792386}
@@ -2386,8 +2393,8 @@ impl dyn Error + Send + Sync {
23862393 pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < Self > > {
23872394 let err: Box < dyn Error > = self ;
23882395 <dyn Error >:: downcast ( err) . map_err ( |s| unsafe {
2389- // Reapply the `Send + Sync` marker .
2390- Box :: from_raw ( Box :: into_raw ( s ) as * mut ( dyn Error + Send + Sync ) )
2396+ // Reapply the `Send + Sync` markers .
2397+ mem :: transmute :: < Box < dyn Error > , Box < dyn Error + Send + Sync > > ( s )
23912398 } )
23922399 }
23932400}
0 commit comments