Skip to content

Commit dd8dd7f

Browse files
committed
Auto merge of rust-lang#130871 - matthiaskrgr:rollup-2cfpxt7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#130820 (Fix diagnostics for coroutines with () as input.) - rust-lang#130833 (Fix the misleading diagnostic for `let_underscore_drop` on type without `Drop` implementation) - rust-lang#130845 (Utf8Chunks: add link to Utf8Chunk) - rust-lang#130860 (Fix directives for lint-non-snake-case-crate) - rust-lang#130861 (Use `mem::offset_of!` for `sockaddr_un.sun_path`) - rust-lang#130865 (Use `&raw` in the standard library) - rust-lang#130868 (Update FIXME comment in s390x_unknown_linux_*.rs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 76ed7a1 + 7a60a7e commit dd8dd7f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+239
-253
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ lint_non_binding_let_multi_suggestion =
531531
consider immediately dropping the value
532532
533533
lint_non_binding_let_on_drop_type =
534-
non-binding let on a type that implements `Drop`
534+
non-binding let on a type that has a destructor
535535
536536
lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
537537
.label = this lock is not assigned to a binding and is immediately dropped

compiler/rustc_lint/src/let_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ declare_lint! {
5151
/// intent.
5252
pub LET_UNDERSCORE_DROP,
5353
Allow,
54-
"non-binding let on a type that implements `Drop`"
54+
"non-binding let on a type that has a destructor"
5555
}
5656

5757
declare_lint! {

compiler/rustc_target/src/spec/targets/s390x_unknown_linux_gnu.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
66
base.endian = Endian::Big;
77
// z10 is the oldest CPU supported by LLVM
88
base.cpu = "z10".into();
9-
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
10-
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
11-
// also strip v128 from the data_layout below to match the older LLVM's expectation.
9+
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
10+
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
1211
base.features = "-vector".into();
1312
base.max_atomic_width = Some(128);
1413
base.min_global_align = Some(16);

compiler/rustc_target/src/spec/targets/s390x_unknown_linux_musl.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
66
base.endian = Endian::Big;
77
// z10 is the oldest CPU supported by LLVM
88
base.cpu = "z10".into();
9-
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
10-
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
11-
// also strip v128 from the data_layout below to match the older LLVM's expectation.
9+
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
10+
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
1211
base.features = "-vector".into();
1312
base.max_atomic_width = Some(128);
1413
base.min_global_align = Some(16);

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+35-37
Original file line numberDiff line numberDiff line change
@@ -2635,49 +2635,47 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
26352635
// This shouldn't be common unless manually implementing one of the
26362636
// traits manually, but don't make it more confusing when it does
26372637
// happen.
2638-
Ok(
2639-
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
2640-
&& not_tupled
2641-
{
2642-
self.report_and_explain_type_error(
2643-
TypeTrace::trait_refs(
2644-
&obligation.cause,
2645-
true,
2646-
expected_trait_ref,
2647-
found_trait_ref,
2648-
),
2649-
ty::error::TypeError::Mismatch,
2650-
)
2651-
} else if found.len() == expected.len() {
2652-
self.report_closure_arg_mismatch(
2653-
span,
2654-
found_span,
2655-
found_trait_ref,
2656-
expected_trait_ref,
2657-
obligation.cause.code(),
2658-
found_node,
2659-
obligation.param_env,
2660-
)
2661-
} else {
2662-
let (closure_span, closure_arg_span, found) = found_did
2663-
.and_then(|did| {
2664-
let node = self.tcx.hir().get_if_local(did)?;
2665-
let (found_span, closure_arg_span, found) =
2666-
self.get_fn_like_arguments(node)?;
2667-
Some((Some(found_span), closure_arg_span, found))
2668-
})
2669-
.unwrap_or((found_span, None, found));
2670-
2671-
self.report_arg_count_mismatch(
2638+
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait() && not_tupled
2639+
{
2640+
return Ok(self.report_and_explain_type_error(
2641+
TypeTrace::trait_refs(&obligation.cause, true, expected_trait_ref, found_trait_ref),
2642+
ty::error::TypeError::Mismatch,
2643+
));
2644+
}
2645+
if found.len() != expected.len() {
2646+
let (closure_span, closure_arg_span, found) = found_did
2647+
.and_then(|did| {
2648+
let node = self.tcx.hir().get_if_local(did)?;
2649+
let (found_span, closure_arg_span, found) = self.get_fn_like_arguments(node)?;
2650+
Some((Some(found_span), closure_arg_span, found))
2651+
})
2652+
.unwrap_or((found_span, None, found));
2653+
2654+
// If the coroutine take a single () as its argument,
2655+
// the trait argument would found the coroutine take 0 arguments,
2656+
// but get_fn_like_arguments would give 1 argument.
2657+
// This would result in "Expected to take 1 argument, but it takes 1 argument".
2658+
// Check again to avoid this.
2659+
if found.len() != expected.len() {
2660+
return Ok(self.report_arg_count_mismatch(
26722661
span,
26732662
closure_span,
26742663
expected,
26752664
found,
26762665
found_trait_ty.is_closure(),
26772666
closure_arg_span,
2678-
)
2679-
},
2680-
)
2667+
));
2668+
}
2669+
}
2670+
Ok(self.report_closure_arg_mismatch(
2671+
span,
2672+
found_span,
2673+
found_trait_ref,
2674+
expected_trait_ref,
2675+
obligation.cause.code(),
2676+
found_node,
2677+
obligation.param_env,
2678+
))
26812679
}
26822680

26832681
/// Given some node representing a fn-like thing in the HIR map,

library/alloc/src/boxed.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ use core::ops::{
199199
DerefPure, DispatchFromDyn, Receiver,
200200
};
201201
use core::pin::{Pin, PinCoerceUnsized};
202-
use core::ptr::{self, NonNull, Unique, addr_of_mut};
202+
use core::ptr::{self, NonNull, Unique};
203203
use core::task::{Context, Poll};
204204
use core::{borrow, fmt, slice};
205205

@@ -1277,7 +1277,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
12771277
#[inline]
12781278
pub fn into_raw(b: Self) -> *mut T {
12791279
// Make sure Miri realizes that we transition from a noalias pointer to a raw pointer here.
1280-
unsafe { addr_of_mut!(*&mut *Self::into_raw_with_allocator(b).0) }
1280+
unsafe { &raw mut *&mut *Self::into_raw_with_allocator(b).0 }
12811281
}
12821282

12831283
/// Consumes the `Box`, returning a wrapped `NonNull` pointer.
@@ -1396,7 +1396,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
13961396
// want *no* aliasing requirements here!
13971397
// In case `A` *is* `Global`, this does not quite have the right behavior; `into_raw`
13981398
// works around that.
1399-
let ptr = addr_of_mut!(**b);
1399+
let ptr = &raw mut **b;
14001400
let alloc = unsafe { ptr::read(&b.1) };
14011401
(ptr, alloc)
14021402
}
@@ -1506,7 +1506,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15061506
pub fn as_mut_ptr(b: &mut Self) -> *mut T {
15071507
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
15081508
// any references.
1509-
ptr::addr_of_mut!(**b)
1509+
&raw mut **b
15101510
}
15111511

15121512
/// Returns a raw pointer to the `Box`'s contents.
@@ -1554,7 +1554,7 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
15541554
pub fn as_ptr(b: &Self) -> *const T {
15551555
// This is a primitive deref, not going through `DerefMut`, and therefore not materializing
15561556
// any references.
1557-
ptr::addr_of!(**b)
1557+
&raw const **b
15581558
}
15591559

15601560
/// Returns a reference to the underlying allocator.

library/alloc/src/boxed/thin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<T: ?Sized> ThinBox<T> {
186186

187187
fn with_header(&self) -> &WithHeader<<T as Pointee>::Metadata> {
188188
// SAFETY: both types are transparent to `NonNull<u8>`
189-
unsafe { &*(core::ptr::addr_of!(self.ptr) as *const WithHeader<_>) }
189+
unsafe { &*((&raw const self.ptr) as *const WithHeader<_>) }
190190
}
191191
}
192192

library/alloc/src/collections/btree/node.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impl<K, V> LeafNode<K, V> {
7272
// be both slightly faster and easier to track in Valgrind.
7373
unsafe {
7474
// parent_idx, keys, and vals are all MaybeUninit
75-
ptr::addr_of_mut!((*this).parent).write(None);
76-
ptr::addr_of_mut!((*this).len).write(0);
75+
(&raw mut (*this).parent).write(None);
76+
(&raw mut (*this).len).write(0);
7777
}
7878
}
7979

@@ -114,7 +114,7 @@ impl<K, V> InternalNode<K, V> {
114114
unsafe {
115115
let mut node = Box::<Self, _>::new_uninit_in(alloc);
116116
// We only need to initialize the data; the edges are MaybeUninit.
117-
LeafNode::init(ptr::addr_of_mut!((*node.as_mut_ptr()).data));
117+
LeafNode::init(&raw mut (*node.as_mut_ptr()).data);
118118
node.assume_init()
119119
}
120120
}
@@ -525,8 +525,8 @@ impl<'a, K, V, Type> NodeRef<marker::ValMut<'a>, K, V, Type> {
525525
// to avoid aliasing with outstanding references to other elements,
526526
// in particular, those returned to the caller in earlier iterations.
527527
let leaf = Self::as_leaf_ptr(&mut self);
528-
let keys = unsafe { ptr::addr_of!((*leaf).keys) };
529-
let vals = unsafe { ptr::addr_of_mut!((*leaf).vals) };
528+
let keys = unsafe { &raw const (*leaf).keys };
529+
let vals = unsafe { &raw mut (*leaf).vals };
530530
// We must coerce to unsized array pointers because of Rust issue #74679.
531531
let keys: *const [_] = keys;
532532
let vals: *mut [_] = vals;

library/alloc/src/rc.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<T, A: Allocator> Rc<T, A> {
787787

788788
let strong = unsafe {
789789
let inner = init_ptr.as_ptr();
790-
ptr::write(ptr::addr_of_mut!((*inner).value), data);
790+
ptr::write(&raw mut (*inner).value, data);
791791

792792
let prev_value = (*inner).strong.get();
793793
debug_assert_eq!(prev_value, 0, "No prior strong references should exist");
@@ -1442,7 +1442,7 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
14421442
// SAFETY: This cannot go through Deref::deref or Rc::inner because
14431443
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
14441444
// write through the pointer after the Rc is recovered through `from_raw`.
1445-
unsafe { ptr::addr_of_mut!((*ptr).value) }
1445+
unsafe { &raw mut (*ptr).value }
14461446
}
14471447

14481448
/// Constructs an `Rc<T, A>` from a raw pointer in the provided allocator.
@@ -2042,8 +2042,8 @@ impl<T: ?Sized> Rc<T> {
20422042
unsafe {
20432043
debug_assert_eq!(Layout::for_value_raw(inner), layout);
20442044

2045-
ptr::addr_of_mut!((*inner).strong).write(Cell::new(1));
2046-
ptr::addr_of_mut!((*inner).weak).write(Cell::new(1));
2045+
(&raw mut (*inner).strong).write(Cell::new(1));
2046+
(&raw mut (*inner).weak).write(Cell::new(1));
20472047
}
20482048

20492049
Ok(inner)
@@ -2072,8 +2072,8 @@ impl<T: ?Sized, A: Allocator> Rc<T, A> {
20722072

20732073
// Copy value as bytes
20742074
ptr::copy_nonoverlapping(
2075-
core::ptr::addr_of!(*src) as *const u8,
2076-
ptr::addr_of_mut!((*ptr).value) as *mut u8,
2075+
(&raw const *src) as *const u8,
2076+
(&raw mut (*ptr).value) as *mut u8,
20772077
value_size,
20782078
);
20792079

@@ -2107,11 +2107,7 @@ impl<T> Rc<[T]> {
21072107
unsafe fn copy_from_slice(v: &[T]) -> Rc<[T]> {
21082108
unsafe {
21092109
let ptr = Self::allocate_for_slice(v.len());
2110-
ptr::copy_nonoverlapping(
2111-
v.as_ptr(),
2112-
ptr::addr_of_mut!((*ptr).value) as *mut T,
2113-
v.len(),
2114-
);
2110+
ptr::copy_nonoverlapping(v.as_ptr(), (&raw mut (*ptr).value) as *mut T, v.len());
21152111
Self::from_ptr(ptr)
21162112
}
21172113
}
@@ -2149,7 +2145,7 @@ impl<T> Rc<[T]> {
21492145
let layout = Layout::for_value_raw(ptr);
21502146

21512147
// Pointer to first element
2152-
let elems = ptr::addr_of_mut!((*ptr).value) as *mut T;
2148+
let elems = (&raw mut (*ptr).value) as *mut T;
21532149

21542150
let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };
21552151

@@ -2577,7 +2573,7 @@ impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for Rc<T, A> {
25772573
#[stable(feature = "rust1", since = "1.0.0")]
25782574
impl<T: ?Sized, A: Allocator> fmt::Pointer for Rc<T, A> {
25792575
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2580-
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
2576+
fmt::Pointer::fmt(&(&raw const **self), f)
25812577
}
25822578
}
25832579

@@ -2718,7 +2714,7 @@ impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
27182714
let (vec_ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();
27192715

27202716
let rc_ptr = Self::allocate_for_slice_in(len, &alloc);
2721-
ptr::copy_nonoverlapping(vec_ptr, ptr::addr_of_mut!((*rc_ptr).value) as *mut T, len);
2717+
ptr::copy_nonoverlapping(vec_ptr, (&raw mut (*rc_ptr).value) as *mut T, len);
27222718

27232719
// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
27242720
// without dropping its contents or the allocator
@@ -3084,7 +3080,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
30843080
// SAFETY: if is_dangling returns false, then the pointer is dereferenceable.
30853081
// The payload may be dropped at this point, and we have to maintain provenance,
30863082
// so use raw pointer manipulation.
3087-
unsafe { ptr::addr_of_mut!((*ptr).value) }
3083+
unsafe { &raw mut (*ptr).value }
30883084
}
30893085
}
30903086

library/alloc/src/sync.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<T, A: Allocator> Arc<T, A> {
797797
// reference into a strong reference.
798798
let strong = unsafe {
799799
let inner = init_ptr.as_ptr();
800-
ptr::write(ptr::addr_of_mut!((*inner).data), data);
800+
ptr::write(&raw mut (*inner).data, data);
801801

802802
// The above write to the data field must be visible to any threads which
803803
// observe a non-zero strong count. Therefore we need at least "Release" ordering
@@ -1583,7 +1583,7 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
15831583
// SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because
15841584
// this is required to retain raw/mut provenance such that e.g. `get_mut` can
15851585
// write through the pointer after the Rc is recovered through `from_raw`.
1586-
unsafe { ptr::addr_of_mut!((*ptr).data) }
1586+
unsafe { &raw mut (*ptr).data }
15871587
}
15881588

15891589
/// Constructs an `Arc<T, A>` from a raw pointer.
@@ -1955,8 +1955,8 @@ impl<T: ?Sized> Arc<T> {
19551955
debug_assert_eq!(unsafe { Layout::for_value_raw(inner) }, layout);
19561956

19571957
unsafe {
1958-
ptr::addr_of_mut!((*inner).strong).write(atomic::AtomicUsize::new(1));
1959-
ptr::addr_of_mut!((*inner).weak).write(atomic::AtomicUsize::new(1));
1958+
(&raw mut (*inner).strong).write(atomic::AtomicUsize::new(1));
1959+
(&raw mut (*inner).weak).write(atomic::AtomicUsize::new(1));
19601960
}
19611961

19621962
inner
@@ -1986,8 +1986,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {
19861986

19871987
// Copy value as bytes
19881988
ptr::copy_nonoverlapping(
1989-
core::ptr::addr_of!(*src) as *const u8,
1990-
ptr::addr_of_mut!((*ptr).data) as *mut u8,
1989+
(&raw const *src) as *const u8,
1990+
(&raw mut (*ptr).data) as *mut u8,
19911991
value_size,
19921992
);
19931993

@@ -2022,7 +2022,7 @@ impl<T> Arc<[T]> {
20222022
unsafe {
20232023
let ptr = Self::allocate_for_slice(v.len());
20242024

2025-
ptr::copy_nonoverlapping(v.as_ptr(), ptr::addr_of_mut!((*ptr).data) as *mut T, v.len());
2025+
ptr::copy_nonoverlapping(v.as_ptr(), (&raw mut (*ptr).data) as *mut T, v.len());
20262026

20272027
Self::from_ptr(ptr)
20282028
}
@@ -2061,7 +2061,7 @@ impl<T> Arc<[T]> {
20612061
let layout = Layout::for_value_raw(ptr);
20622062

20632063
// Pointer to first element
2064-
let elems = ptr::addr_of_mut!((*ptr).data) as *mut T;
2064+
let elems = (&raw mut (*ptr).data) as *mut T;
20652065

20662066
let mut guard = Guard { mem: NonNull::new_unchecked(mem), elems, layout, n_elems: 0 };
20672067

@@ -2805,7 +2805,7 @@ impl<T: ?Sized, A: Allocator> Weak<T, A> {
28052805
// SAFETY: if is_dangling returns false, then the pointer is dereferenceable.
28062806
// The payload may be dropped at this point, and we have to maintain provenance,
28072807
// so use raw pointer manipulation.
2808-
unsafe { ptr::addr_of_mut!((*ptr).data) }
2808+
unsafe { &raw mut (*ptr).data }
28092809
}
28102810
}
28112811

@@ -3428,7 +3428,7 @@ impl<T: ?Sized + fmt::Debug, A: Allocator> fmt::Debug for Arc<T, A> {
34283428
#[stable(feature = "rust1", since = "1.0.0")]
34293429
impl<T: ?Sized, A: Allocator> fmt::Pointer for Arc<T, A> {
34303430
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3431-
fmt::Pointer::fmt(&core::ptr::addr_of!(**self), f)
3431+
fmt::Pointer::fmt(&(&raw const **self), f)
34323432
}
34333433
}
34343434

@@ -3678,7 +3678,7 @@ impl<T, A: Allocator + Clone> From<Vec<T, A>> for Arc<[T], A> {
36783678
let (vec_ptr, len, cap, alloc) = v.into_raw_parts_with_alloc();
36793679

36803680
let rc_ptr = Self::allocate_for_slice_in(len, &alloc);
3681-
ptr::copy_nonoverlapping(vec_ptr, ptr::addr_of_mut!((*rc_ptr).data) as *mut T, len);
3681+
ptr::copy_nonoverlapping(vec_ptr, (&raw mut (*rc_ptr).data) as *mut T, len);
36823682

36833683
// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
36843684
// without dropping its contents or the allocator

library/alloc/src/vec/into_iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use crate::raw_vec::RawVec;
2121
macro non_null {
2222
(mut $place:expr, $t:ident) => {{
2323
#![allow(unused_unsafe)] // we're sometimes used within an unsafe block
24-
unsafe { &mut *(ptr::addr_of_mut!($place) as *mut NonNull<$t>) }
24+
unsafe { &mut *((&raw mut $place) as *mut NonNull<$t>) }
2525
}},
2626
($place:expr, $t:ident) => {{
2727
#![allow(unused_unsafe)] // we're sometimes used within an unsafe block
28-
unsafe { *(ptr::addr_of!($place) as *const NonNull<$t>) }
28+
unsafe { *((&raw const $place) as *const NonNull<$t>) }
2929
}},
3030
}
3131

0 commit comments

Comments
 (0)