Skip to content

Commit ce55b20

Browse files
committed
Auto merge of rust-lang#135357 - jhpratt:rollup-gs00yt3, r=jhpratt
Rollup of 6 pull requests Successful merges: - rust-lang#134074 (bootstrap: `std::io::ErrorKind::CrossesDevices` is finally stable) - rust-lang#135236 (Update a bunch of library types for MCP807) - rust-lang#135301 (re-add a warning for old master branch, but with much simpler logic) - rust-lang#135324 (Initial fs module for uefi) - rust-lang#135326 (support target specific `optimized-compiler-builtins`) - rust-lang#135347 (Use `NonNull::without_provenance` within the standard library) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7e4077d + 46222ce commit ce55b20

File tree

30 files changed

+748
-250
lines changed

30 files changed

+748
-250
lines changed

config.example.toml

+9
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,15 @@
922922
# argument as the test binary.
923923
#runner = <none> (string)
924924

925+
# Use the optimized LLVM C intrinsics for `compiler_builtins`, rather than Rust intrinsics
926+
# on this target.
927+
# Requires the LLVM submodule to be managed by bootstrap (i.e. not external) so that `compiler-rt`
928+
# sources are available.
929+
#
930+
# Setting this to `false` generates slower code, but removes the requirement for a C toolchain in
931+
# order to run `x check`.
932+
#optimized-compiler-builtins = build.optimized-compiler-builtins (bool)
933+
925934
# =============================================================================
926935
# Distribution options
927936
#

library/alloc/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
#![feature(local_waker)]
127127
#![feature(maybe_uninit_slice)]
128128
#![feature(maybe_uninit_uninit_array_transpose)]
129+
#![feature(nonnull_provenance)]
129130
#![feature(panic_internals)]
130131
#![feature(pattern)]
131132
#![feature(pin_coerce_unsized_trait)]
@@ -142,6 +143,7 @@
142143
#![feature(slice_range)]
143144
#![feature(std_internals)]
144145
#![feature(str_internals)]
146+
#![feature(temporary_niche_types)]
145147
#![feature(trusted_fused)]
146148
#![feature(trusted_len)]
147149
#![feature(trusted_random_access)]

library/alloc/src/raw_vec.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,15 @@ enum AllocInit {
3333
Zeroed,
3434
}
3535

36-
#[repr(transparent)]
37-
#[cfg_attr(target_pointer_width = "16", rustc_layout_scalar_valid_range_end(0x7fff))]
38-
#[cfg_attr(target_pointer_width = "32", rustc_layout_scalar_valid_range_end(0x7fff_ffff))]
39-
#[cfg_attr(target_pointer_width = "64", rustc_layout_scalar_valid_range_end(0x7fff_ffff_ffff_ffff))]
40-
struct Cap(usize);
36+
type Cap = core::num::niche_types::UsizeNoHighBit;
4137

42-
impl Cap {
43-
const ZERO: Cap = unsafe { Cap(0) };
38+
const ZERO_CAP: Cap = unsafe { Cap::new_unchecked(0) };
4439

45-
/// `Cap(cap)`, except if `T` is a ZST then `Cap::ZERO`.
46-
///
47-
/// # Safety: cap must be <= `isize::MAX`.
48-
unsafe fn new<T>(cap: usize) -> Self {
49-
if T::IS_ZST { Cap::ZERO } else { unsafe { Self(cap) } }
50-
}
40+
/// `Cap(cap)`, except if `T` is a ZST then `Cap::ZERO`.
41+
///
42+
/// # Safety: cap must be <= `isize::MAX`.
43+
unsafe fn new_cap<T>(cap: usize) -> Cap {
44+
if T::IS_ZST { ZERO_CAP } else { unsafe { Cap::new_unchecked(cap) } }
5145
}
5246

5347
/// A low-level utility for more ergonomically allocating, reallocating, and deallocating
@@ -257,7 +251,7 @@ impl<T, A: Allocator> RawVec<T, A> {
257251
// SAFETY: Precondition passed to the caller
258252
unsafe {
259253
let ptr = ptr.cast();
260-
let capacity = Cap::new::<T>(capacity);
254+
let capacity = new_cap::<T>(capacity);
261255
Self {
262256
inner: RawVecInner::from_raw_parts_in(ptr, capacity, alloc),
263257
_marker: PhantomData,
@@ -275,7 +269,7 @@ impl<T, A: Allocator> RawVec<T, A> {
275269
// SAFETY: Precondition passed to the caller
276270
unsafe {
277271
let ptr = ptr.cast();
278-
let capacity = Cap::new::<T>(capacity);
272+
let capacity = new_cap::<T>(capacity);
279273
Self { inner: RawVecInner::from_nonnull_in(ptr, capacity, alloc), _marker: PhantomData }
280274
}
281275
}
@@ -410,7 +404,7 @@ impl<A: Allocator> RawVecInner<A> {
410404
const fn new_in(alloc: A, align: usize) -> Self {
411405
let ptr = unsafe { core::mem::transmute(align) };
412406
// `cap: 0` means "unallocated". zero-sized types are ignored.
413-
Self { ptr, cap: Cap::ZERO, alloc }
407+
Self { ptr, cap: ZERO_CAP, alloc }
414408
}
415409

416410
#[cfg(not(no_global_oom_handling))]
@@ -483,7 +477,11 @@ impl<A: Allocator> RawVecInner<A> {
483477
// Allocators currently return a `NonNull<[u8]>` whose length
484478
// matches the size requested. If that ever changes, the capacity
485479
// here should change to `ptr.len() / mem::size_of::<T>()`.
486-
Ok(Self { ptr: Unique::from(ptr.cast()), cap: unsafe { Cap(capacity) }, alloc })
480+
Ok(Self {
481+
ptr: Unique::from(ptr.cast()),
482+
cap: unsafe { Cap::new_unchecked(capacity) },
483+
alloc,
484+
})
487485
}
488486

489487
#[inline]
@@ -508,7 +506,7 @@ impl<A: Allocator> RawVecInner<A> {
508506

509507
#[inline]
510508
const fn capacity(&self, elem_size: usize) -> usize {
511-
if elem_size == 0 { usize::MAX } else { self.cap.0 }
509+
if elem_size == 0 { usize::MAX } else { self.cap.as_inner() }
512510
}
513511

514512
#[inline]
@@ -518,15 +516,15 @@ impl<A: Allocator> RawVecInner<A> {
518516

519517
#[inline]
520518
fn current_memory(&self, elem_layout: Layout) -> Option<(NonNull<u8>, Layout)> {
521-
if elem_layout.size() == 0 || self.cap.0 == 0 {
519+
if elem_layout.size() == 0 || self.cap.as_inner() == 0 {
522520
None
523521
} else {
524522
// We could use Layout::array here which ensures the absence of isize and usize overflows
525523
// and could hypothetically handle differences between stride and size, but this memory
526524
// has already been allocated so we know it can't overflow and currently Rust does not
527525
// support such types. So we can do better by skipping some checks and avoid an unwrap.
528526
unsafe {
529-
let alloc_size = elem_layout.size().unchecked_mul(self.cap.0);
527+
let alloc_size = elem_layout.size().unchecked_mul(self.cap.as_inner());
530528
let layout = Layout::from_size_align_unchecked(alloc_size, elem_layout.align());
531529
Some((self.ptr.into(), layout))
532530
}
@@ -562,7 +560,7 @@ impl<A: Allocator> RawVecInner<A> {
562560
#[inline]
563561
#[track_caller]
564562
fn grow_one(&mut self, elem_layout: Layout) {
565-
if let Err(err) = self.grow_amortized(self.cap.0, 1, elem_layout) {
563+
if let Err(err) = self.grow_amortized(self.cap.as_inner(), 1, elem_layout) {
566564
handle_error(err);
567565
}
568566
}
@@ -627,7 +625,7 @@ impl<A: Allocator> RawVecInner<A> {
627625
// the size requested. If that ever changes, the capacity here should
628626
// change to `ptr.len() / mem::size_of::<T>()`.
629627
self.ptr = Unique::from(ptr.cast());
630-
self.cap = unsafe { Cap(cap) };
628+
self.cap = unsafe { Cap::new_unchecked(cap) };
631629
}
632630

633631
fn grow_amortized(
@@ -650,7 +648,7 @@ impl<A: Allocator> RawVecInner<A> {
650648

651649
// This guarantees exponential growth. The doubling cannot overflow
652650
// because `cap <= isize::MAX` and the type of `cap` is `usize`.
653-
let cap = cmp::max(self.cap.0 * 2, required_cap);
651+
let cap = cmp::max(self.cap.as_inner() * 2, required_cap);
654652
let cap = cmp::max(min_non_zero_cap(elem_layout.size()), cap);
655653

656654
let new_layout = layout_array(cap, elem_layout)?;
@@ -719,7 +717,7 @@ impl<A: Allocator> RawVecInner<A> {
719717
unsafe { self.alloc.deallocate(ptr, layout) };
720718
self.ptr =
721719
unsafe { Unique::new_unchecked(ptr::without_provenance_mut(elem_layout.align())) };
722-
self.cap = Cap::ZERO;
720+
self.cap = ZERO_CAP;
723721
} else {
724722
let ptr = unsafe {
725723
// Layout cannot overflow here because it would have

library/alloc/src/rc.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ use core::intrinsics::abort;
252252
use core::iter;
253253
use core::marker::{PhantomData, Unsize};
254254
use core::mem::{self, ManuallyDrop, align_of_val_raw};
255+
use core::num::NonZeroUsize;
255256
use core::ops::{CoerceUnsized, Deref, DerefMut, DerefPure, DispatchFromDyn, LegacyReceiver};
256257
use core::panic::{RefUnwindSafe, UnwindSafe};
257258
#[cfg(not(no_global_oom_handling))]
@@ -3027,12 +3028,7 @@ impl<T> Weak<T> {
30273028
#[rustc_const_stable(feature = "const_weak_new", since = "1.73.0")]
30283029
#[must_use]
30293030
pub const fn new() -> Weak<T> {
3030-
Weak {
3031-
ptr: unsafe {
3032-
NonNull::new_unchecked(ptr::without_provenance_mut::<RcInner<T>>(usize::MAX))
3033-
},
3034-
alloc: Global,
3035-
}
3031+
Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc: Global }
30363032
}
30373033
}
30383034

@@ -3054,12 +3050,7 @@ impl<T, A: Allocator> Weak<T, A> {
30543050
#[inline]
30553051
#[unstable(feature = "allocator_api", issue = "32838")]
30563052
pub fn new_in(alloc: A) -> Weak<T, A> {
3057-
Weak {
3058-
ptr: unsafe {
3059-
NonNull::new_unchecked(ptr::without_provenance_mut::<RcInner<T>>(usize::MAX))
3060-
},
3061-
alloc,
3062-
}
3053+
Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc }
30633054
}
30643055
}
30653056

library/alloc/src/sync.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core::intrinsics::abort;
1818
use core::iter;
1919
use core::marker::{PhantomData, Unsize};
2020
use core::mem::{self, ManuallyDrop, align_of_val_raw};
21+
use core::num::NonZeroUsize;
2122
use core::ops::{CoerceUnsized, Deref, DerefPure, DispatchFromDyn, LegacyReceiver};
2223
use core::panic::{RefUnwindSafe, UnwindSafe};
2324
use core::pin::{Pin, PinCoerceUnsized};
@@ -2687,12 +2688,7 @@ impl<T> Weak<T> {
26872688
#[rustc_const_stable(feature = "const_weak_new", since = "1.73.0")]
26882689
#[must_use]
26892690
pub const fn new() -> Weak<T> {
2690-
Weak {
2691-
ptr: unsafe {
2692-
NonNull::new_unchecked(ptr::without_provenance_mut::<ArcInner<T>>(usize::MAX))
2693-
},
2694-
alloc: Global,
2695-
}
2691+
Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc: Global }
26962692
}
26972693
}
26982694

@@ -2717,12 +2713,7 @@ impl<T, A: Allocator> Weak<T, A> {
27172713
#[inline]
27182714
#[unstable(feature = "allocator_api", issue = "32838")]
27192715
pub fn new_in(alloc: A) -> Weak<T, A> {
2720-
Weak {
2721-
ptr: unsafe {
2722-
NonNull::new_unchecked(ptr::without_provenance_mut::<ArcInner<T>>(usize::MAX))
2723-
},
2724-
alloc,
2725-
}
2716+
Weak { ptr: NonNull::without_provenance(NonZeroUsize::MAX), alloc }
27262717
}
27272718
}
27282719

library/core/src/alloc/layout.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ impl Layout {
233233
#[must_use]
234234
#[inline]
235235
pub const fn dangling(&self) -> NonNull<u8> {
236-
// SAFETY: align is guaranteed to be non-zero
237-
unsafe { NonNull::new_unchecked(crate::ptr::without_provenance_mut::<u8>(self.align())) }
236+
NonNull::without_provenance(self.align.as_nonzero())
238237
}
239238

240239
/// Creates a layout describing the record that can hold a value

library/core/src/num/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ mod overflow_panic;
5151
mod saturating;
5252
mod wrapping;
5353

54+
/// 100% perma-unstable
55+
#[doc(hidden)]
56+
pub mod niche_types;
57+
5458
#[stable(feature = "rust1", since = "1.0.0")]
5559
#[cfg(not(no_fp_fmt_parse))]
5660
pub use dec2flt::ParseFloatError;

0 commit comments

Comments
 (0)