Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #130871

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ lint_non_binding_let_multi_suggestion =
consider immediately dropping the value
lint_non_binding_let_on_drop_type =
non-binding let on a type that implements `Drop`
non-binding let on a type that has a destructor
lint_non_binding_let_on_sync_lock = non-binding let on a synchronization lock
.label = this lock is not assigned to a binding and is immediately dropped
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/let_underscore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ declare_lint! {
/// intent.
pub LET_UNDERSCORE_DROP,
Allow,
"non-binding let on a type that implements `Drop`"
"non-binding let on a type that has a destructor"
}

declare_lint! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
base.endian = Endian::Big;
// z10 is the oldest CPU supported by LLVM
base.cpu = "z10".into();
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
// also strip v128 from the data_layout below to match the older LLVM's expectation.
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".into();
base.max_atomic_width = Some(128);
base.min_global_align = Some(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ pub(crate) fn target() -> Target {
base.endian = Endian::Big;
// z10 is the oldest CPU supported by LLVM
base.cpu = "z10".into();
// FIXME: The ABI implementation in cabi_s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption. On LLVM < 16, we
// also strip v128 from the data_layout below to match the older LLVM's expectation.
// FIXME: The ABI implementation in abi/call/s390x.rs is for now hard-coded to assume the no-vector
// ABI. Pass the -vector feature string to LLVM to respect this assumption.
base.features = "-vector".into();
base.max_atomic_width = Some(128);
base.min_global_align = Some(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2635,49 +2635,47 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// This shouldn't be common unless manually implementing one of the
// traits manually, but don't make it more confusing when it does
// happen.
Ok(
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait()
&& not_tupled
{
self.report_and_explain_type_error(
TypeTrace::trait_refs(
&obligation.cause,
true,
expected_trait_ref,
found_trait_ref,
),
ty::error::TypeError::Mismatch,
)
} else if found.len() == expected.len() {
self.report_closure_arg_mismatch(
span,
found_span,
found_trait_ref,
expected_trait_ref,
obligation.cause.code(),
found_node,
obligation.param_env,
)
} else {
let (closure_span, closure_arg_span, found) = found_did
.and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?;
let (found_span, closure_arg_span, found) =
self.get_fn_like_arguments(node)?;
Some((Some(found_span), closure_arg_span, found))
})
.unwrap_or((found_span, None, found));

self.report_arg_count_mismatch(
if Some(expected_trait_ref.def_id) != self.tcx.lang_items().coroutine_trait() && not_tupled
{
return Ok(self.report_and_explain_type_error(
TypeTrace::trait_refs(&obligation.cause, true, expected_trait_ref, found_trait_ref),
ty::error::TypeError::Mismatch,
));
}
if found.len() != expected.len() {
let (closure_span, closure_arg_span, found) = found_did
.and_then(|did| {
let node = self.tcx.hir().get_if_local(did)?;
let (found_span, closure_arg_span, found) = self.get_fn_like_arguments(node)?;
Some((Some(found_span), closure_arg_span, found))
})
.unwrap_or((found_span, None, found));

// If the coroutine take a single () as its argument,
// the trait argument would found the coroutine take 0 arguments,
// but get_fn_like_arguments would give 1 argument.
// This would result in "Expected to take 1 argument, but it takes 1 argument".
// Check again to avoid this.
if found.len() != expected.len() {
return Ok(self.report_arg_count_mismatch(
span,
closure_span,
expected,
found,
found_trait_ty.is_closure(),
closure_arg_span,
)
},
)
));
}
}
Ok(self.report_closure_arg_mismatch(
span,
found_span,
found_trait_ref,
expected_trait_ref,
obligation.cause.code(),
found_node,
obligation.param_env,
))
}

/// Given some node representing a fn-like thing in the HIR map,
Expand Down
10 changes: 5 additions & 5 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ use core::ops::{
DerefPure, DispatchFromDyn, Receiver,
};
use core::pin::{Pin, PinCoerceUnsized};
use core::ptr::{self, NonNull, Unique, addr_of_mut};
use core::ptr::{self, NonNull, Unique};
use core::task::{Context, Poll};
use core::{borrow, fmt, slice};

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

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

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

/// Returns a reference to the underlying allocator.
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/boxed/thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<T: ?Sized> ThinBox<T> {

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

Expand Down
10 changes: 5 additions & 5 deletions library/alloc/src/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ impl<K, V> LeafNode<K, V> {
// be both slightly faster and easier to track in Valgrind.
unsafe {
// parent_idx, keys, and vals are all MaybeUninit
ptr::addr_of_mut!((*this).parent).write(None);
ptr::addr_of_mut!((*this).len).write(0);
(&raw mut (*this).parent).write(None);
(&raw mut (*this).len).write(0);
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ impl<K, V> InternalNode<K, V> {
unsafe {
let mut node = Box::<Self, _>::new_uninit_in(alloc);
// We only need to initialize the data; the edges are MaybeUninit.
LeafNode::init(ptr::addr_of_mut!((*node.as_mut_ptr()).data));
LeafNode::init(&raw mut (*node.as_mut_ptr()).data);
node.assume_init()
}
}
Expand Down Expand Up @@ -525,8 +525,8 @@ impl<'a, K, V, Type> NodeRef<marker::ValMut<'a>, K, V, Type> {
// to avoid aliasing with outstanding references to other elements,
// in particular, those returned to the caller in earlier iterations.
let leaf = Self::as_leaf_ptr(&mut self);
let keys = unsafe { ptr::addr_of!((*leaf).keys) };
let vals = unsafe { ptr::addr_of_mut!((*leaf).vals) };
let keys = unsafe { &raw const (*leaf).keys };
let vals = unsafe { &raw mut (*leaf).vals };
// We must coerce to unsized array pointers because of Rust issue #74679.
let keys: *const [_] = keys;
let vals: *mut [_] = vals;
Expand Down
26 changes: 11 additions & 15 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ impl<T, A: Allocator> Rc<T, A> {

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

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

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

ptr::addr_of_mut!((*inner).strong).write(Cell::new(1));
ptr::addr_of_mut!((*inner).weak).write(Cell::new(1));
(&raw mut (*inner).strong).write(Cell::new(1));
(&raw mut (*inner).weak).write(Cell::new(1));
}

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

// Copy value as bytes
ptr::copy_nonoverlapping(
core::ptr::addr_of!(*src) as *const u8,
ptr::addr_of_mut!((*ptr).value) as *mut u8,
(&raw const *src) as *const u8,
(&raw mut (*ptr).value) as *mut u8,
value_size,
);

Expand Down Expand Up @@ -2107,11 +2107,7 @@ impl<T> Rc<[T]> {
unsafe fn copy_from_slice(v: &[T]) -> Rc<[T]> {
unsafe {
let ptr = Self::allocate_for_slice(v.len());
ptr::copy_nonoverlapping(
v.as_ptr(),
ptr::addr_of_mut!((*ptr).value) as *mut T,
v.len(),
);
ptr::copy_nonoverlapping(v.as_ptr(), (&raw mut (*ptr).value) as *mut T, v.len());
Self::from_ptr(ptr)
}
}
Expand Down Expand Up @@ -2149,7 +2145,7 @@ impl<T> Rc<[T]> {
let layout = Layout::for_value_raw(ptr);

// Pointer to first element
let elems = ptr::addr_of_mut!((*ptr).value) as *mut T;
let elems = (&raw mut (*ptr).value) as *mut T;

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

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

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

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

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

Expand Down
22 changes: 11 additions & 11 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ impl<T, A: Allocator> Arc<T, A> {
// reference into a strong reference.
let strong = unsafe {
let inner = init_ptr.as_ptr();
ptr::write(ptr::addr_of_mut!((*inner).data), data);
ptr::write(&raw mut (*inner).data, data);

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

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

unsafe {
ptr::addr_of_mut!((*inner).strong).write(atomic::AtomicUsize::new(1));
ptr::addr_of_mut!((*inner).weak).write(atomic::AtomicUsize::new(1));
(&raw mut (*inner).strong).write(atomic::AtomicUsize::new(1));
(&raw mut (*inner).weak).write(atomic::AtomicUsize::new(1));
}

inner
Expand Down Expand Up @@ -1986,8 +1986,8 @@ impl<T: ?Sized, A: Allocator> Arc<T, A> {

// Copy value as bytes
ptr::copy_nonoverlapping(
core::ptr::addr_of!(*src) as *const u8,
ptr::addr_of_mut!((*ptr).data) as *mut u8,
(&raw const *src) as *const u8,
(&raw mut (*ptr).data) as *mut u8,
value_size,
);

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

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

Self::from_ptr(ptr)
}
Expand Down Expand Up @@ -2061,7 +2061,7 @@ impl<T> Arc<[T]> {
let layout = Layout::for_value_raw(ptr);

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

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

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

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

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

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

// Create a `Vec<T, &A>` with length 0, to deallocate the buffer
// without dropping its contents or the allocator
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use crate::raw_vec::RawVec;
macro non_null {
(mut $place:expr, $t:ident) => {{
#![allow(unused_unsafe)] // we're sometimes used within an unsafe block
unsafe { &mut *(ptr::addr_of_mut!($place) as *mut NonNull<$t>) }
unsafe { &mut *((&raw mut $place) as *mut NonNull<$t>) }
}},
($place:expr, $t:ident) => {{
#![allow(unused_unsafe)] // we're sometimes used within an unsafe block
unsafe { *(ptr::addr_of!($place) as *const NonNull<$t>) }
unsafe { *((&raw const $place) as *const NonNull<$t>) }
}},
}

Expand Down
Loading
Loading