Skip to content

Commit ed369ff

Browse files
committed
Auto merge of rust-lang#148721 - Zalathar:rollup-398va3y, r=Zalathar
Rollup of 22 pull requests Successful merges: - rust-lang#128666 (Add `overflow_checks` intrinsic) - rust-lang#146305 (Add correct suggestion for multi-references for self type in method) - rust-lang#147179 ([DebugInfo] Fix container types failing to find template args) - rust-lang#147743 (Show packed field alignment in mir_transform_unaligned_packed_ref) - rust-lang#148079 (Rename `downcast_[ref|mut]_unchecked` -> `downcast_unchecked_[ref|mut]`) - rust-lang#148084 (Optimize path components iteration on platforms that don't have prefixes) - rust-lang#148126 (Fix rust stdlib build failing for VxWorks) - rust-lang#148204 (Modify contributor email entries in .mailmap) - rust-lang#148279 (rustc_builtin_macros: rename bench parameter to avoid collisions with user-defined function names) - rust-lang#148333 (constify result unwrap unchecked) - rust-lang#148539 (Add Allocator proxy impls for Box, Rc, and Arc) - rust-lang#148601 (`invalid_atomic_ordering`: also lint `update` & `try_update`) - rust-lang#148612 (Add note for identifier with attempted hygiene violation) - rust-lang#148613 (Switch hexagon targets to rust-lld) - rust-lang#148619 (Enable std locking functions on AIX) - rust-lang#148644 ([bootstrap] Make `--open` option work with `doc src/tools/error_index_generator`) - rust-lang#148649 (don't completely reset `HeadUsages`) - rust-lang#148673 (Remove a remnant of `dyn*` from the parser) - rust-lang#148675 (Remove eslint-js from npm dependencies) - rust-lang#148680 (Recover `[T: N]` as `[T; N]`) - rust-lang#148688 (Remove unused argument `features` from `eval_config_entry`) - rust-lang#148711 (Use the current lint note id when parsing `cfg!()`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 716a276 + 064302d commit ed369ff

File tree

16 files changed

+286
-53
lines changed

16 files changed

+286
-53
lines changed

alloc/src/boxed.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,3 +2241,55 @@ impl<E: Error> Error for Box<E> {
22412241
Error::provide(&**self, request);
22422242
}
22432243
}
2244+
2245+
#[unstable(feature = "allocator_api", issue = "32838")]
2246+
unsafe impl<T: ?Sized + Allocator, A: Allocator> Allocator for Box<T, A> {
2247+
#[inline]
2248+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
2249+
(**self).allocate(layout)
2250+
}
2251+
2252+
#[inline]
2253+
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
2254+
(**self).allocate_zeroed(layout)
2255+
}
2256+
2257+
#[inline]
2258+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
2259+
// SAFETY: the safety contract must be upheld by the caller
2260+
unsafe { (**self).deallocate(ptr, layout) }
2261+
}
2262+
2263+
#[inline]
2264+
unsafe fn grow(
2265+
&self,
2266+
ptr: NonNull<u8>,
2267+
old_layout: Layout,
2268+
new_layout: Layout,
2269+
) -> Result<NonNull<[u8]>, AllocError> {
2270+
// SAFETY: the safety contract must be upheld by the caller
2271+
unsafe { (**self).grow(ptr, old_layout, new_layout) }
2272+
}
2273+
2274+
#[inline]
2275+
unsafe fn grow_zeroed(
2276+
&self,
2277+
ptr: NonNull<u8>,
2278+
old_layout: Layout,
2279+
new_layout: Layout,
2280+
) -> Result<NonNull<[u8]>, AllocError> {
2281+
// SAFETY: the safety contract must be upheld by the caller
2282+
unsafe { (**self).grow_zeroed(ptr, old_layout, new_layout) }
2283+
}
2284+
2285+
#[inline]
2286+
unsafe fn shrink(
2287+
&self,
2288+
ptr: NonNull<u8>,
2289+
old_layout: Layout,
2290+
new_layout: Layout,
2291+
) -> Result<NonNull<[u8]>, AllocError> {
2292+
// SAFETY: the safety contract must be upheld by the caller
2293+
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
2294+
}
2295+
}

alloc/src/rc.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,3 +4413,55 @@ impl<T: ?Sized, A: Allocator> Drop for UniqueRcUninit<T, A> {
44134413
}
44144414
}
44154415
}
4416+
4417+
#[unstable(feature = "allocator_api", issue = "32838")]
4418+
unsafe impl<T: ?Sized + Allocator, A: Allocator> Allocator for Rc<T, A> {
4419+
#[inline]
4420+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
4421+
(**self).allocate(layout)
4422+
}
4423+
4424+
#[inline]
4425+
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
4426+
(**self).allocate_zeroed(layout)
4427+
}
4428+
4429+
#[inline]
4430+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
4431+
// SAFETY: the safety contract must be upheld by the caller
4432+
unsafe { (**self).deallocate(ptr, layout) }
4433+
}
4434+
4435+
#[inline]
4436+
unsafe fn grow(
4437+
&self,
4438+
ptr: NonNull<u8>,
4439+
old_layout: Layout,
4440+
new_layout: Layout,
4441+
) -> Result<NonNull<[u8]>, AllocError> {
4442+
// SAFETY: the safety contract must be upheld by the caller
4443+
unsafe { (**self).grow(ptr, old_layout, new_layout) }
4444+
}
4445+
4446+
#[inline]
4447+
unsafe fn grow_zeroed(
4448+
&self,
4449+
ptr: NonNull<u8>,
4450+
old_layout: Layout,
4451+
new_layout: Layout,
4452+
) -> Result<NonNull<[u8]>, AllocError> {
4453+
// SAFETY: the safety contract must be upheld by the caller
4454+
unsafe { (**self).grow_zeroed(ptr, old_layout, new_layout) }
4455+
}
4456+
4457+
#[inline]
4458+
unsafe fn shrink(
4459+
&self,
4460+
ptr: NonNull<u8>,
4461+
old_layout: Layout,
4462+
new_layout: Layout,
4463+
) -> Result<NonNull<[u8]>, AllocError> {
4464+
// SAFETY: the safety contract must be upheld by the caller
4465+
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
4466+
}
4467+
}

alloc/src/sync.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,3 +4780,55 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for UniqueArc<T, A> {
47804780
unsafe { ptr::drop_in_place(&mut (*self.ptr.as_ptr()).data) };
47814781
}
47824782
}
4783+
4784+
#[unstable(feature = "allocator_api", issue = "32838")]
4785+
unsafe impl<T: ?Sized + Allocator, A: Allocator> Allocator for Arc<T, A> {
4786+
#[inline]
4787+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
4788+
(**self).allocate(layout)
4789+
}
4790+
4791+
#[inline]
4792+
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
4793+
(**self).allocate_zeroed(layout)
4794+
}
4795+
4796+
#[inline]
4797+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
4798+
// SAFETY: the safety contract must be upheld by the caller
4799+
unsafe { (**self).deallocate(ptr, layout) }
4800+
}
4801+
4802+
#[inline]
4803+
unsafe fn grow(
4804+
&self,
4805+
ptr: NonNull<u8>,
4806+
old_layout: Layout,
4807+
new_layout: Layout,
4808+
) -> Result<NonNull<[u8]>, AllocError> {
4809+
// SAFETY: the safety contract must be upheld by the caller
4810+
unsafe { (**self).grow(ptr, old_layout, new_layout) }
4811+
}
4812+
4813+
#[inline]
4814+
unsafe fn grow_zeroed(
4815+
&self,
4816+
ptr: NonNull<u8>,
4817+
old_layout: Layout,
4818+
new_layout: Layout,
4819+
) -> Result<NonNull<[u8]>, AllocError> {
4820+
// SAFETY: the safety contract must be upheld by the caller
4821+
unsafe { (**self).grow_zeroed(ptr, old_layout, new_layout) }
4822+
}
4823+
4824+
#[inline]
4825+
unsafe fn shrink(
4826+
&self,
4827+
ptr: NonNull<u8>,
4828+
old_layout: Layout,
4829+
new_layout: Layout,
4830+
) -> Result<NonNull<[u8]>, AllocError> {
4831+
// SAFETY: the safety contract must be upheld by the caller
4832+
unsafe { (**self).shrink(ptr, old_layout, new_layout) }
4833+
}
4834+
}

core/src/any.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl dyn Any {
227227
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
228228
// that check for memory safety because we have implemented Any for all types; no other
229229
// impls can exist as they would conflict with our impl.
230-
unsafe { Some(self.downcast_ref_unchecked()) }
230+
unsafe { Some(self.downcast_unchecked_ref()) }
231231
} else {
232232
None
233233
}
@@ -263,7 +263,7 @@ impl dyn Any {
263263
// SAFETY: just checked whether we are pointing to the correct type, and we can rely on
264264
// that check for memory safety because we have implemented Any for all types; no other
265265
// impls can exist as they would conflict with our impl.
266-
unsafe { Some(self.downcast_mut_unchecked()) }
266+
unsafe { Some(self.downcast_unchecked_mut()) }
267267
} else {
268268
None
269269
}
@@ -281,7 +281,7 @@ impl dyn Any {
281281
/// let x: Box<dyn Any> = Box::new(1_usize);
282282
///
283283
/// unsafe {
284-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
284+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
285285
/// }
286286
/// ```
287287
///
@@ -291,7 +291,7 @@ impl dyn Any {
291291
/// with the incorrect type is *undefined behavior*.
292292
#[unstable(feature = "downcast_unchecked", issue = "90850")]
293293
#[inline]
294-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
294+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
295295
debug_assert!(self.is::<T>());
296296
// SAFETY: caller guarantees that T is the correct type
297297
unsafe { &*(self as *const dyn Any as *const T) }
@@ -309,7 +309,7 @@ impl dyn Any {
309309
/// let mut x: Box<dyn Any> = Box::new(1_usize);
310310
///
311311
/// unsafe {
312-
/// *x.downcast_mut_unchecked::<usize>() += 1;
312+
/// *x.downcast_unchecked_mut::<usize>() += 1;
313313
/// }
314314
///
315315
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -321,7 +321,7 @@ impl dyn Any {
321321
/// with the incorrect type is *undefined behavior*.
322322
#[unstable(feature = "downcast_unchecked", issue = "90850")]
323323
#[inline]
324-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
324+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
325325
debug_assert!(self.is::<T>());
326326
// SAFETY: caller guarantees that T is the correct type
327327
unsafe { &mut *(self as *mut dyn Any as *mut T) }
@@ -417,7 +417,7 @@ impl dyn Any + Send {
417417
/// let x: Box<dyn Any> = Box::new(1_usize);
418418
///
419419
/// unsafe {
420-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
420+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
421421
/// }
422422
/// ```
423423
///
@@ -427,9 +427,9 @@ impl dyn Any + Send {
427427
/// with the incorrect type is *undefined behavior*.
428428
#[unstable(feature = "downcast_unchecked", issue = "90850")]
429429
#[inline]
430-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
430+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
431431
// SAFETY: guaranteed by caller
432-
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
432+
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
433433
}
434434

435435
/// Forwards to the method defined on the type `dyn Any`.
@@ -444,7 +444,7 @@ impl dyn Any + Send {
444444
/// let mut x: Box<dyn Any> = Box::new(1_usize);
445445
///
446446
/// unsafe {
447-
/// *x.downcast_mut_unchecked::<usize>() += 1;
447+
/// *x.downcast_unchecked_mut::<usize>() += 1;
448448
/// }
449449
///
450450
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -456,9 +456,9 @@ impl dyn Any + Send {
456456
/// with the incorrect type is *undefined behavior*.
457457
#[unstable(feature = "downcast_unchecked", issue = "90850")]
458458
#[inline]
459-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
459+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
460460
// SAFETY: guaranteed by caller
461-
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
461+
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
462462
}
463463
}
464464

@@ -551,7 +551,7 @@ impl dyn Any + Send + Sync {
551551
/// let x: Box<dyn Any> = Box::new(1_usize);
552552
///
553553
/// unsafe {
554-
/// assert_eq!(*x.downcast_ref_unchecked::<usize>(), 1);
554+
/// assert_eq!(*x.downcast_unchecked_ref::<usize>(), 1);
555555
/// }
556556
/// ```
557557
/// # Safety
@@ -560,9 +560,9 @@ impl dyn Any + Send + Sync {
560560
/// with the incorrect type is *undefined behavior*.
561561
#[unstable(feature = "downcast_unchecked", issue = "90850")]
562562
#[inline]
563-
pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T {
563+
pub unsafe fn downcast_unchecked_ref<T: Any>(&self) -> &T {
564564
// SAFETY: guaranteed by caller
565-
unsafe { <dyn Any>::downcast_ref_unchecked::<T>(self) }
565+
unsafe { <dyn Any>::downcast_unchecked_ref::<T>(self) }
566566
}
567567

568568
/// Forwards to the method defined on the type `Any`.
@@ -577,7 +577,7 @@ impl dyn Any + Send + Sync {
577577
/// let mut x: Box<dyn Any> = Box::new(1_usize);
578578
///
579579
/// unsafe {
580-
/// *x.downcast_mut_unchecked::<usize>() += 1;
580+
/// *x.downcast_unchecked_mut::<usize>() += 1;
581581
/// }
582582
///
583583
/// assert_eq!(*x.downcast_ref::<usize>().unwrap(), 2);
@@ -588,9 +588,9 @@ impl dyn Any + Send + Sync {
588588
/// with the incorrect type is *undefined behavior*.
589589
#[unstable(feature = "downcast_unchecked", issue = "90850")]
590590
#[inline]
591-
pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T {
591+
pub unsafe fn downcast_unchecked_mut<T: Any>(&mut self) -> &mut T {
592592
// SAFETY: guaranteed by caller
593-
unsafe { <dyn Any>::downcast_mut_unchecked::<T>(self) }
593+
unsafe { <dyn Any>::downcast_unchecked_mut::<T>(self) }
594594
}
595595
}
596596

core/src/intrinsics/mod.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2589,6 +2589,24 @@ pub const fn ub_checks() -> bool {
25892589
cfg!(ub_checks)
25902590
}
25912591

2592+
/// Returns whether we should perform some overflow-checking at runtime. This eventually evaluates to
2593+
/// `cfg!(overflow_checks)`, but behaves different from `cfg!` when mixing crates built with different
2594+
/// flags: if the crate has overflow checks enabled or carries the `#[rustc_inherit_overflow_checks]`
2595+
/// attribute, evaluation is delayed until monomorphization (or until the call gets inlined into
2596+
/// a crate that does not delay evaluation further); otherwise it can happen any time.
2597+
///
2598+
/// The common case here is a user program built with overflow_checks linked against the distributed
2599+
/// sysroot which is built without overflow_checks but with `#[rustc_inherit_overflow_checks]`.
2600+
/// For code that gets monomorphized in the user crate (i.e., generic functions and functions with
2601+
/// `#[inline]`), gating assertions on `overflow_checks()` rather than `cfg!(overflow_checks)` means that
2602+
/// assertions are enabled whenever the *user crate* has overflow checks enabled. However if the
2603+
/// user has overflow checks disabled, the checks will still get optimized out.
2604+
#[inline(always)]
2605+
#[rustc_intrinsic]
2606+
pub const fn overflow_checks() -> bool {
2607+
cfg!(debug_assertions)
2608+
}
2609+
25922610
/// Allocates a block of memory at compile time.
25932611
/// At runtime, just returns a null pointer.
25942612
///

core/src/result.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,11 +1646,16 @@ impl<T, E> Result<T, E> {
16461646
#[inline]
16471647
#[track_caller]
16481648
#[stable(feature = "option_result_unwrap_unchecked", since = "1.58.0")]
1649-
pub unsafe fn unwrap_unchecked(self) -> T {
1649+
#[rustc_const_unstable(feature = "const_result_unwrap_unchecked", issue = "148714")]
1650+
pub const unsafe fn unwrap_unchecked(self) -> T {
16501651
match self {
16511652
Ok(t) => t,
1652-
// SAFETY: the safety contract must be upheld by the caller.
1653-
Err(_) => unsafe { hint::unreachable_unchecked() },
1653+
Err(e) => {
1654+
// FIXME(const-hack): to avoid E: const Destruct bound
1655+
super::mem::forget(e);
1656+
// SAFETY: the safety contract must be upheld by the caller.
1657+
unsafe { hint::unreachable_unchecked() }
1658+
}
16541659
}
16551660
}
16561661

std/benches/path.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ fn bench_path_cmp_fast_path_short(b: &mut test::Bencher) {
5555
});
5656
}
5757

58+
#[bench]
59+
fn bench_path_components_iter(b: &mut test::Bencher) {
60+
let p = Path::new("/my/home/is/my/castle/and/my/castle/has/a/rusty/workbench/");
61+
62+
b.iter(|| {
63+
for c in black_box(p).components() {
64+
black_box(c);
65+
}
66+
})
67+
}
68+
69+
#[bench]
70+
fn bench_path_file_name(b: &mut test::Bencher) {
71+
let p1 = Path::new("foo.bar");
72+
let p2 = Path::new("foo/bar");
73+
let p3 = Path::new("/bar");
74+
75+
b.iter(|| {
76+
black_box(black_box(p1).file_name());
77+
black_box(black_box(p2).file_name());
78+
black_box(black_box(p3).file_name());
79+
})
80+
}
81+
5882
#[bench]
5983
#[cfg_attr(miri, ignore)] // Miri isn't fast...
6084
fn bench_path_hashset(b: &mut test::Bencher) {

0 commit comments

Comments
 (0)