Skip to content

Commit df6c197

Browse files
committed
Auto merge of rust-lang#121569 - matthiaskrgr:rollup-awglrax, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#121343 (Add examples for some methods on slices) - rust-lang#121374 (match lowering: Split off `test_candidates` into several functions and improve comments) - rust-lang#121474 (Ignore compiletest test directive migration commits) - rust-lang#121515 (promotion: don't promote int::MIN / -1) - rust-lang#121530 (Fix incorrect doc of ScopedJoinHandle::is_finished) - rust-lang#121551 (Forbid use of `extern "C-unwind"` inside standard library) - rust-lang#121556 (Use `addr_of!`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0a0d083 + ae9a855 commit df6c197

File tree

40 files changed

+97
-76
lines changed

40 files changed

+97
-76
lines changed

alloc/src/boxed/thin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<T: ?Sized> ThinBox<T> {
176176

177177
fn with_header(&self) -> &WithHeader<<T as Pointee>::Metadata> {
178178
// SAFETY: both types are transparent to `NonNull<u8>`
179-
unsafe { &*((&self.ptr) as *const WithOpaqueHeader as *const WithHeader<_>) }
179+
unsafe { &*(core::ptr::addr_of!(self.ptr) as *const WithHeader<_>) }
180180
}
181181
}
182182

alloc/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
#![warn(multiple_supertrait_upcastable)]
9393
#![allow(internal_features)]
9494
#![allow(rustdoc::redundant_explicit_links)]
95+
#![deny(ffi_unwind_calls)]
9596
//
9697
// Library features:
9798
// tidy-alphabetical-start

alloc/src/rc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
19691969

19701970
// Copy value as bytes
19711971
ptr::copy_nonoverlapping(
1972-
&*src as *const T as *const u8,
1972+
core::ptr::addr_of!(*src) as *const u8,
19731973
ptr::addr_of_mut!((*ptr).value) as *mut u8,
19741974
value_size,
19751975
);
@@ -2440,7 +2440,7 @@ impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for Rc<T, A> {
24402440
#[stable(feature = "rust1", since = "1.0.0")]
24412441
impl<T: ?Sized, A: Allocator> fmt::Pointer for Rc<T, A> {
24422442
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2443-
fmt::Pointer::fmt(&(&**self as *const T), f)
2443+
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
24442444
}
24452445
}
24462446

alloc/src/sync.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,7 +1914,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
19141914

19151915
// Copy value as bytes
19161916
ptr::copy_nonoverlapping(
1917-
&*src as *const T as *const u8,
1917+
core::ptr::addr_of!(*src) as *const u8,
19181918
ptr::addr_of_mut!((*ptr).data) as *mut u8,
19191919
value_size,
19201920
);
@@ -3265,7 +3265,7 @@ impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for Arc<T, A> {
32653265
#[stable(feature = "rust1", since = "1.0.0")]
32663266
impl<T: ?Sized, A: Allocator> fmt::Pointer for Arc<T, A> {
32673267
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3268-
fmt::Pointer::fmt(&(&**self as *const T), f)
3268+
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
32693269
}
32703270
}
32713271

core/src/ffi/c_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::ffi::c_char;
44
use crate::fmt;
55
use crate::intrinsics;
66
use crate::ops;
7+
use crate::ptr::addr_of;
78
use crate::slice;
89
use crate::slice::memchr;
910
use crate::str;
@@ -603,7 +604,7 @@ impl CStr {
603604
pub const fn to_bytes_with_nul(&self) -> &[u8] {
604605
// SAFETY: Transmuting a slice of `c_char`s to a slice of `u8`s
605606
// is safe on all supported targets.
606-
unsafe { &*(&self.inner as *const [c_char] as *const [u8]) }
607+
unsafe { &*(addr_of!(self.inner) as *const [u8]) }
607608
}
608609

609610
/// Yields a <code>&[str]</code> slice if the `CStr` contains valid UTF-8.

core/src/iter/adapters/filter_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedF
22
use crate::mem::{ManuallyDrop, MaybeUninit};
33
use crate::num::NonZero;
44
use crate::ops::{ControlFlow, Try};
5+
use crate::ptr::addr_of;
56
use crate::{array, fmt};
67

78
/// An iterator that uses `f` to both filter and map elements from `iter`.
@@ -98,9 +99,8 @@ where
9899
// SAFETY: Loop conditions ensure the index is in bounds.
99100

100101
unsafe {
101-
let opt_payload_at: *const MaybeUninit<B> = (&val as *const Option<B>)
102-
.byte_add(core::mem::offset_of!(Option<B>, Some.0))
103-
.cast();
102+
let opt_payload_at: *const MaybeUninit<B> =
103+
addr_of!(val).byte_add(core::mem::offset_of!(Option<B>, Some.0)).cast();
104104
let dst = guard.array.as_mut_ptr().add(idx);
105105
crate::ptr::copy_nonoverlapping(opt_payload_at, dst, 1);
106106
crate::mem::forget(val);

core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
#![allow(incomplete_features)]
107107
#![warn(multiple_supertrait_upcastable)]
108108
#![allow(internal_features)]
109+
#![deny(ffi_unwind_calls)]
109110
// Do not check link redundancy on bootstraping phase
110111
#![allow(rustdoc::redundant_explicit_links)]
111112
//

core/src/ptr/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ pub const unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
15531553
// `dst` cannot overlap `src` because the caller has mutable access
15541554
// to `dst` while `src` is owned by this function.
15551555
unsafe {
1556-
copy_nonoverlapping(&src as *const T as *const u8, dst as *mut u8, mem::size_of::<T>());
1556+
copy_nonoverlapping(addr_of!(src) as *const u8, dst as *mut u8, mem::size_of::<T>());
15571557
// We are calling the intrinsic directly to avoid function calls in the generated code.
15581558
intrinsics::forget(src);
15591559
}

core/src/slice/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ impl<T> [T] {
146146
/// ```
147147
/// let a = [1, 2, 3];
148148
/// assert!(!a.is_empty());
149+
///
150+
/// let b: &[i32] = &[];
151+
/// assert!(b.is_empty());
149152
/// ```
150153
#[stable(feature = "rust1", since = "1.0.0")]
151154
#[rustc_const_stable(feature = "const_slice_is_empty", since = "1.39.0")]
@@ -185,6 +188,9 @@ impl<T> [T] {
185188
/// *first = 5;
186189
/// }
187190
/// assert_eq!(x, &[5, 1, 2]);
191+
///
192+
/// let y: &mut [i32] = &mut [];
193+
/// assert_eq!(None, y.first_mut());
188194
/// ```
189195
#[stable(feature = "rust1", since = "1.0.0")]
190196
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
@@ -297,7 +303,7 @@ impl<T> [T] {
297303
if let [.., last] = self { Some(last) } else { None }
298304
}
299305

300-
/// Returns a mutable reference to the last item in the slice.
306+
/// Returns a mutable reference to the last item in the slice, or `None` if it is empty.
301307
///
302308
/// # Examples
303309
///
@@ -308,6 +314,9 @@ impl<T> [T] {
308314
/// *last = 10;
309315
/// }
310316
/// assert_eq!(x, &[0, 1, 10]);
317+
///
318+
/// let y: &mut [i32] = &mut [];
319+
/// assert_eq!(None, y.last_mut());
311320
/// ```
312321
#[stable(feature = "rust1", since = "1.0.0")]
313322
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]

proc_macro/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#![feature(strict_provenance)]
3737
#![recursion_limit = "256"]
3838
#![allow(internal_features)]
39+
#![deny(ffi_unwind_calls)]
3940

4041
#[unstable(feature = "proc_macro_internals", issue = "27812")]
4142
#[doc(hidden)]

0 commit comments

Comments
 (0)