145
145
//! to `into_iter()` for boxed slices will defer to the slice implementation on editions before
146
146
//! 2024:
147
147
//!
148
- #![ cfg_attr( bootstrap, doc = "```rust,edition2021,ignore" ) ]
149
- #![ cfg_attr( not( bootstrap) , doc = "```rust,edition2021" ) ]
148
+ //! ```rust,edition2021
150
149
//! // Rust 2015, 2018, and 2021:
151
150
//!
152
151
//! # #![allow(boxed_slice_into_iter)] // override our `deny(warnings)`
189
188
use core:: any:: Any ;
190
189
use core:: async_iter:: AsyncIterator ;
191
190
use core:: borrow;
191
+ #[ cfg( not( no_global_oom_handling) ) ]
192
+ use core:: clone:: CloneToUninit ;
192
193
use core:: cmp:: Ordering ;
193
194
use core:: error:: Error ;
194
195
use core:: fmt;
@@ -208,7 +209,7 @@ use core::slice;
208
209
use core:: task:: { Context , Poll } ;
209
210
210
211
#[ cfg( not( no_global_oom_handling) ) ]
211
- use crate :: alloc:: { handle_alloc_error, WriteCloneIntoRaw } ;
212
+ use crate :: alloc:: handle_alloc_error;
212
213
use crate :: alloc:: { AllocError , Allocator , Global , Layout } ;
213
214
#[ cfg( not( no_global_oom_handling) ) ]
214
215
use crate :: borrow:: Cow ;
@@ -1212,6 +1213,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1212
1213
/// let static_ref: &'static mut usize = Box::leak(x);
1213
1214
/// *static_ref += 1;
1214
1215
/// 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) });
1215
1219
/// ```
1216
1220
///
1217
1221
/// Unsized data:
@@ -1221,6 +1225,9 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
1221
1225
/// let static_ref = Box::leak(x);
1222
1226
/// static_ref[0] = 4;
1223
1227
/// 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) });
1224
1231
/// ```
1225
1232
#[ stable( feature = "box_leak" , since = "1.26.0" ) ]
1226
1233
#[ inline]
@@ -1347,7 +1354,7 @@ impl<T: Clone, A: Allocator + Clone> Clone for Box<T, A> {
1347
1354
// Pre-allocate memory to allow writing the cloned value directly.
1348
1355
let mut boxed = Self :: new_uninit_in ( self . 1 . clone ( ) ) ;
1349
1356
unsafe {
1350
- ( * * self ) . write_clone_into_raw ( boxed. as_mut_ptr ( ) ) ;
1357
+ ( * * self ) . clone_to_uninit ( boxed. as_mut_ptr ( ) ) ;
1351
1358
boxed. assume_init ( )
1352
1359
}
1353
1360
}
@@ -2123,23 +2130,23 @@ impl<I> FromIterator<I> for Box<[I]> {
2123
2130
2124
2131
/// This implementation is required to make sure that the `Box<[I]>: IntoIterator`
2125
2132
/// 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 " ) ]
2127
2134
impl < I , A : Allocator > !Iterator for Box < [ I ] , A > { }
2128
2135
2129
2136
/// This implementation is required to make sure that the `&Box<[I]>: IntoIterator`
2130
2137
/// 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 " ) ]
2132
2139
impl < ' a , I , A : Allocator > !Iterator for & ' a Box < [ I ] , A > { }
2133
2140
2134
2141
/// This implementation is required to make sure that the `&mut Box<[I]>: IntoIterator`
2135
2142
/// 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 " ) ]
2137
2144
impl < ' a , I , A : Allocator > !Iterator for & ' a mut Box < [ I ] , A > { }
2138
2145
2139
2146
// Note: the `#[rustc_skip_during_method_dispatch(boxed_slice)]` on `trait IntoIterator`
2140
2147
// hides this implementation from explicit `.into_iter()` calls on editions < 2024,
2141
2148
// 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 " ) ]
2143
2150
impl < I , A : Allocator > IntoIterator for Box < [ I ] , A > {
2144
2151
type IntoIter = vec:: IntoIter < I , A > ;
2145
2152
type Item = I ;
@@ -2148,7 +2155,7 @@ impl<I, A: Allocator> IntoIterator for Box<[I], A> {
2148
2155
}
2149
2156
}
2150
2157
2151
- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2158
+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
2152
2159
impl < ' a , I , A : Allocator > IntoIterator for & ' a Box < [ I ] , A > {
2153
2160
type IntoIter = slice:: Iter < ' a , I > ;
2154
2161
type Item = & ' a I ;
@@ -2157,7 +2164,7 @@ impl<'a, I, A: Allocator> IntoIterator for &'a Box<[I], A> {
2157
2164
}
2158
2165
}
2159
2166
2160
- #[ stable( feature = "boxed_slice_into_iter" , since = "CURRENT_RUSTC_VERSION " ) ]
2167
+ #[ stable( feature = "boxed_slice_into_iter" , since = "1.80.0 " ) ]
2161
2168
impl < ' a , I , A : Allocator > IntoIterator for & ' a mut Box < [ I ] , A > {
2162
2169
type IntoIter = slice:: IterMut < ' a , I > ;
2163
2170
type Item = & ' a mut I ;
@@ -2167,47 +2174,47 @@ impl<'a, I, A: Allocator> IntoIterator for &'a mut Box<[I], A> {
2167
2174
}
2168
2175
2169
2176
#[ 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 " ) ]
2171
2178
impl FromIterator < char > for Box < str > {
2172
2179
fn from_iter < T : IntoIterator < Item = char > > ( iter : T ) -> Self {
2173
2180
String :: from_iter ( iter) . into_boxed_str ( )
2174
2181
}
2175
2182
}
2176
2183
2177
2184
#[ 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 " ) ]
2179
2186
impl < ' a > FromIterator < & ' a char > for Box < str > {
2180
2187
fn from_iter < T : IntoIterator < Item = & ' a char > > ( iter : T ) -> Self {
2181
2188
String :: from_iter ( iter) . into_boxed_str ( )
2182
2189
}
2183
2190
}
2184
2191
2185
2192
#[ 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 " ) ]
2187
2194
impl < ' a > FromIterator < & ' a str > for Box < str > {
2188
2195
fn from_iter < T : IntoIterator < Item = & ' a str > > ( iter : T ) -> Self {
2189
2196
String :: from_iter ( iter) . into_boxed_str ( )
2190
2197
}
2191
2198
}
2192
2199
2193
2200
#[ 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 " ) ]
2195
2202
impl FromIterator < String > for Box < str > {
2196
2203
fn from_iter < T : IntoIterator < Item = String > > ( iter : T ) -> Self {
2197
2204
String :: from_iter ( iter) . into_boxed_str ( )
2198
2205
}
2199
2206
}
2200
2207
2201
2208
#[ 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 " ) ]
2203
2210
impl < A : Allocator > FromIterator < Box < str , A > > for Box < str > {
2204
2211
fn from_iter < T : IntoIterator < Item = Box < str , A > > > ( iter : T ) -> Self {
2205
2212
String :: from_iter ( iter) . into_boxed_str ( )
2206
2213
}
2207
2214
}
2208
2215
2209
2216
#[ 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 " ) ]
2211
2218
impl < ' a > FromIterator < Cow < ' a , str > > for Box < str > {
2212
2219
fn from_iter < T : IntoIterator < Item = Cow < ' a , str > > > ( iter : T ) -> Self {
2213
2220
String :: from_iter ( iter) . into_boxed_str ( )
@@ -2373,7 +2380,7 @@ impl dyn Error + Send {
2373
2380
let err: Box < dyn Error > = self ;
2374
2381
<dyn Error >:: downcast ( err) . map_err ( |s| unsafe {
2375
2382
// 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 )
2377
2384
} )
2378
2385
}
2379
2386
}
@@ -2386,8 +2393,8 @@ impl dyn Error + Send + Sync {
2386
2393
pub fn downcast < T : Error + ' static > ( self : Box < Self > ) -> Result < Box < T > , Box < Self > > {
2387
2394
let err: Box < dyn Error > = self ;
2388
2395
<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 )
2391
2398
} )
2392
2399
}
2393
2400
}
0 commit comments