Skip to content

Commit 8ea71ae

Browse files
committed
Auto merge of rust-lang#129563 - matthiaskrgr:rollup-t6bai2d, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#129091 (add Box::as_ptr and Box::as_mut_ptr methods) - rust-lang#129134 (bootstrap: improve error recovery flags to curl) - rust-lang#129416 (library: Move unstable API of new_uninit to new features) - rust-lang#129459 (handle stage0 `cargo` and `rustc` separately) - rust-lang#129487 (repr_transparent_external_private_fields: special-case some std types) - rust-lang#129511 (Update minifier to 0.3.1) - rust-lang#129523 (Make `rustc_type_ir` build on stable) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4de4deb + a994fbb commit 8ea71ae

File tree

9 files changed

+113
-11
lines changed

9 files changed

+113
-11
lines changed

Diff for: alloc/src/boxed.rs

+95-3
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ impl<T> Box<T> {
293293
///
294294
/// ```
295295
/// #![feature(new_uninit)]
296+
/// #![feature(new_zeroed_alloc)]
296297
///
297298
/// let zero = Box::<u32>::new_zeroed();
298299
/// let zero = unsafe { zero.assume_init() };
@@ -303,7 +304,7 @@ impl<T> Box<T> {
303304
/// [zeroed]: mem::MaybeUninit::zeroed
304305
#[cfg(not(no_global_oom_handling))]
305306
#[inline]
306-
#[unstable(feature = "new_uninit", issue = "63291")]
307+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
307308
#[must_use]
308309
pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
309310
Self::new_zeroed_in(Global)
@@ -684,6 +685,7 @@ impl<T> Box<[T]> {
684685
/// # Examples
685686
///
686687
/// ```
688+
/// #![feature(new_zeroed_alloc)]
687689
/// #![feature(new_uninit)]
688690
///
689691
/// let values = Box::<[u32]>::new_zeroed_slice(3);
@@ -694,7 +696,7 @@ impl<T> Box<[T]> {
694696
///
695697
/// [zeroed]: mem::MaybeUninit::zeroed
696698
#[cfg(not(no_global_oom_handling))]
697-
#[unstable(feature = "new_uninit", issue = "63291")]
699+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
698700
#[must_use]
699701
pub fn new_zeroed_slice(len: usize) -> Box<[mem::MaybeUninit<T>]> {
700702
unsafe { RawVec::with_capacity_zeroed(len).into_box(len) }
@@ -955,6 +957,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
955957
/// # Examples
956958
///
957959
/// ```
960+
/// #![feature(box_uninit_write)]
958961
/// #![feature(new_uninit)]
959962
///
960963
/// let big_box = Box::<[usize; 1024]>::new_uninit();
@@ -972,7 +975,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
972975
/// assert_eq!(*x, i);
973976
/// }
974977
/// ```
975-
#[unstable(feature = "new_uninit", issue = "63291")]
978+
#[unstable(feature = "box_uninit_write", issue = "129397")]
976979
#[inline]
977980
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
978981
unsafe {
@@ -1254,6 +1257,95 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12541257
unsafe { (Unique::from(&mut *ptr), alloc) }
12551258
}
12561259

1260+
/// Returns a raw mutable pointer to the `Box`'s contents.
1261+
///
1262+
/// The caller must ensure that the `Box` outlives the pointer this
1263+
/// function returns, or else it will end up dangling.
1264+
///
1265+
/// This method guarantees that for the purpose of the aliasing model, this method
1266+
/// does not materialize a reference to the underlying memory, and thus the returned pointer
1267+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1268+
/// Note that calling other methods that materialize references to the memory
1269+
/// may still invalidate this pointer.
1270+
/// See the example below for how this guarantee can be used.
1271+
///
1272+
/// # Examples
1273+
///
1274+
/// Due to the aliasing guarantee, the following code is legal:
1275+
///
1276+
/// ```rust
1277+
/// #![feature(box_as_ptr)]
1278+
///
1279+
/// unsafe {
1280+
/// let mut b = Box::new(0);
1281+
/// let ptr1 = Box::as_mut_ptr(&mut b);
1282+
/// ptr1.write(1);
1283+
/// let ptr2 = Box::as_mut_ptr(&mut b);
1284+
/// ptr2.write(2);
1285+
/// // Notably, the write to `ptr2` did *not* invalidate `ptr1`:
1286+
/// ptr1.write(3);
1287+
/// }
1288+
/// ```
1289+
///
1290+
/// [`as_mut_ptr`]: Self::as_mut_ptr
1291+
/// [`as_ptr`]: Self::as_ptr
1292+
#[unstable(feature = "box_as_ptr", issue = "129090")]
1293+
#[rustc_never_returns_null_ptr]
1294+
#[inline]
1295+
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
1296+
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
1297+
// any references.
1298+
ptr::addr_of_mut!(**b)
1299+
}
1300+
1301+
/// Returns a raw pointer to the `Box`'s contents.
1302+
///
1303+
/// The caller must ensure that the `Box` outlives the pointer this
1304+
/// function returns, or else it will end up dangling.
1305+
///
1306+
/// The caller must also ensure that the memory the pointer (non-transitively) points to
1307+
/// is never written to (except inside an `UnsafeCell`) using this pointer or any pointer
1308+
/// derived from it. If you need to mutate the contents of the `Box`, use [`as_mut_ptr`].
1309+
///
1310+
/// This method guarantees that for the purpose of the aliasing model, this method
1311+
/// does not materialize a reference to the underlying memory, and thus the returned pointer
1312+
/// will remain valid when mixed with other calls to [`as_ptr`] and [`as_mut_ptr`].
1313+
/// Note that calling other methods that materialize mutable references to the memory,
1314+
/// as well as writing to this memory, may still invalidate this pointer.
1315+
/// See the example below for how this guarantee can be used.
1316+
///
1317+
/// # Examples
1318+
///
1319+
/// Due to the aliasing guarantee, the following code is legal:
1320+
///
1321+
/// ```rust
1322+
/// #![feature(box_as_ptr)]
1323+
///
1324+
/// unsafe {
1325+
/// let mut v = Box::new(0);
1326+
/// let ptr1 = Box::as_ptr(&v);
1327+
/// let ptr2 = Box::as_mut_ptr(&mut v);
1328+
/// let _val = ptr2.read();
1329+
/// // No write to this memory has happened yet, so `ptr1` is still valid.
1330+
/// let _val = ptr1.read();
1331+
/// // However, once we do a write...
1332+
/// ptr2.write(1);
1333+
/// // ... `ptr1` is no longer valid.
1334+
/// // This would be UB: let _val = ptr1.read();
1335+
/// }
1336+
/// ```
1337+
///
1338+
/// [`as_mut_ptr`]: Self::as_mut_ptr
1339+
/// [`as_ptr`]: Self::as_ptr
1340+
#[unstable(feature = "box_as_ptr", issue = "129090")]
1341+
#[rustc_never_returns_null_ptr]
1342+
#[inline]
1343+
pub fn as_ptr(b: &Self) -> *const T {
1344+
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
1345+
// any references.
1346+
ptr::addr_of!(**b)
1347+
}
1348+
12571349
/// Returns a reference to the underlying allocator.
12581350
///
12591351
/// Note: this is an associated function, which means that you have

Diff for: alloc/src/rc.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ impl<T> Rc<T> {
539539
/// # Examples
540540
///
541541
/// ```
542+
/// #![feature(new_zeroed_alloc)]
542543
/// #![feature(new_uninit)]
543544
///
544545
/// use std::rc::Rc;
@@ -551,7 +552,7 @@ impl<T> Rc<T> {
551552
///
552553
/// [zeroed]: mem::MaybeUninit::zeroed
553554
#[cfg(not(no_global_oom_handling))]
554-
#[unstable(feature = "new_uninit", issue = "63291")]
555+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
555556
#[must_use]
556557
pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
557558
unsafe {
@@ -1000,6 +1001,7 @@ impl<T> Rc<[T]> {
10001001
///
10011002
/// ```
10021003
/// #![feature(new_uninit)]
1004+
/// #![feature(new_zeroed_alloc)]
10031005
///
10041006
/// use std::rc::Rc;
10051007
///
@@ -1011,7 +1013,7 @@ impl<T> Rc<[T]> {
10111013
///
10121014
/// [zeroed]: mem::MaybeUninit::zeroed
10131015
#[cfg(not(no_global_oom_handling))]
1014-
#[unstable(feature = "new_uninit", issue = "63291")]
1016+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
10151017
#[must_use]
10161018
pub fn new_zeroed_slice(len: usize) -> Rc<[mem::MaybeUninit<T>]> {
10171019
unsafe {

Diff for: alloc/src/sync.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ impl<T> Arc<T> {
542542
/// # Examples
543543
///
544544
/// ```
545+
/// #![feature(new_zeroed_alloc)]
545546
/// #![feature(new_uninit)]
546547
///
547548
/// use std::sync::Arc;
@@ -555,7 +556,7 @@ impl<T> Arc<T> {
555556
/// [zeroed]: mem::MaybeUninit::zeroed
556557
#[cfg(not(no_global_oom_handling))]
557558
#[inline]
558-
#[unstable(feature = "new_uninit", issue = "63291")]
559+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
559560
#[must_use]
560561
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
561562
unsafe {
@@ -1134,6 +1135,7 @@ impl<T> Arc<[T]> {
11341135
/// # Examples
11351136
///
11361137
/// ```
1138+
/// #![feature(new_zeroed_alloc)]
11371139
/// #![feature(new_uninit)]
11381140
///
11391141
/// use std::sync::Arc;
@@ -1147,7 +1149,7 @@ impl<T> Arc<[T]> {
11471149
/// [zeroed]: mem::MaybeUninit::zeroed
11481150
#[cfg(not(no_global_oom_handling))]
11491151
#[inline]
1150-
#[unstable(feature = "new_uninit", issue = "63291")]
1152+
#[unstable(feature = "new_zeroed_alloc", issue = "129396")]
11511153
#[must_use]
11521154
pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
11531155
unsafe {
@@ -1191,7 +1193,7 @@ impl<T, A: Allocator> Arc<[T], A> {
11911193
/// assert_eq!(*values, [1, 2, 3])
11921194
/// ```
11931195
#[cfg(not(no_global_oom_handling))]
1194-
#[unstable(feature = "new_uninit", issue = "63291")]
1196+
#[unstable(feature = "allocator_api", issue = "32838")]
11951197
#[inline]
11961198
pub fn new_uninit_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
11971199
unsafe { Arc::from_ptr_in(Arc::allocate_for_slice_in(len, &alloc), alloc) }
@@ -1220,7 +1222,7 @@ impl<T, A: Allocator> Arc<[T], A> {
12201222
///
12211223
/// [zeroed]: mem::MaybeUninit::zeroed
12221224
#[cfg(not(no_global_oom_handling))]
1223-
#[unstable(feature = "new_uninit", issue = "63291")]
1225+
#[unstable(feature = "allocator_api", issue = "32838")]
12241226
#[inline]
12251227
pub fn new_zeroed_slice_in(len: usize, alloc: A) -> Arc<[mem::MaybeUninit<T>], A> {
12261228
unsafe {

Diff for: alloc/src/vec/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ impl<T, A: Allocator> Vec<T, A> {
13341334
self.buf.ptr()
13351335
}
13361336

1337-
/// Returns an unsafe mutable pointer to the vector's buffer, or a dangling
1337+
/// Returns a raw mutable pointer to the vector's buffer, or a dangling
13381338
/// raw pointer valid for zero sized reads if the vector didn't allocate.
13391339
///
13401340
/// The caller must ensure that the vector outlives the pointer this
@@ -1350,7 +1350,6 @@ impl<T, A: Allocator> Vec<T, A> {
13501350
/// may still invalidate this pointer.
13511351
/// See the second example below for how this guarantee can be used.
13521352
///
1353-
///
13541353
/// # Examples
13551354
///
13561355
/// ```

Diff for: core/src/cell.rs

+3
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ pub use once::OnceCell;
306306
/// See the [module-level documentation](self) for more.
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
#[repr(transparent)]
309+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
309310
pub struct Cell<T: ?Sized> {
310311
value: UnsafeCell<T>,
311312
}
@@ -2055,6 +2056,7 @@ impl<T: ?Sized + fmt::Display> fmt::Display for RefMut<'_, T> {
20552056
#[lang = "unsafe_cell"]
20562057
#[stable(feature = "rust1", since = "1.0.0")]
20572058
#[repr(transparent)]
2059+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
20582060
pub struct UnsafeCell<T: ?Sized> {
20592061
value: T,
20602062
}
@@ -2297,6 +2299,7 @@ impl<T> UnsafeCell<*mut T> {
22972299
/// See [`UnsafeCell`] for details.
22982300
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
22992301
#[repr(transparent)]
2302+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
23002303
pub struct SyncUnsafeCell<T: ?Sized> {
23012304
value: UnsafeCell<T>,
23022305
}

Diff for: core/src/mem/manually_drop.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ use crate::ptr;
4747
#[lang = "manually_drop"]
4848
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
4949
#[repr(transparent)]
50+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
5051
pub struct ManuallyDrop<T: ?Sized> {
5152
value: T,
5253
}

Diff for: core/src/mem/maybe_uninit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ use crate::{fmt, intrinsics, ptr, slice};
237237
#[lang = "maybe_uninit"]
238238
#[derive(Copy)]
239239
#[repr(transparent)]
240+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
240241
pub union MaybeUninit<T> {
241242
uninit: (),
242243
value: ManuallyDrop<T>,

Diff for: core/src/pin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ use crate::{cmp, fmt};
10841084
#[lang = "pin"]
10851085
#[fundamental]
10861086
#[repr(transparent)]
1087+
#[cfg_attr(not(bootstrap), rustc_pub_transparent)]
10871088
#[derive(Copy, Clone)]
10881089
pub struct Pin<Ptr> {
10891090
// FIXME(#93176): this field is made `#[unstable] #[doc(hidden)] pub` to:

Diff for: std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@
363363
#![feature(get_mut_unchecked)]
364364
#![feature(map_try_insert)]
365365
#![feature(new_uninit)]
366+
#![feature(new_zeroed_alloc)]
366367
#![feature(slice_concat_trait)]
367368
#![feature(thin_box)]
368369
#![feature(try_reserve_kind)]

0 commit comments

Comments
 (0)