Skip to content

Commit

Permalink
Auto merge of rust-lang#131792 - matthiaskrgr:rollup-480nwg4, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#130822 (Add `from_ref` and `from_mut` constructors to `core::ptr::NonNull`.)
 - rust-lang#131381 (Implement edition 2024 match ergonomics restrictions)
 - rust-lang#131594 (rustdoc: Rename "object safe" to "dyn compatible")
 - rust-lang#131686 (Add fast-path when computing the default visibility)
 - rust-lang#131699 (Try to improve error messages involving aliases in the solver)
 - rust-lang#131757 (Ignore lint-non-snake-case-crate#proc_macro_ on targets without unwind)
 - rust-lang#131783 (Fix explicit_iter_loop in rustc_serialize)
 - rust-lang#131788 (Fix mismatched quotation mark)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 16, 2024
2 parents f7b3231 + 1581f56 commit 1e13241
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#![feature(isqrt)]
#![feature(lazy_get)]
#![feature(link_cfg)]
#![feature(non_null_from_ref)]
#![feature(offset_of_enum)]
#![feature(panic_internals)]
#![feature(ptr_alignment_type)]
Expand Down
28 changes: 22 additions & 6 deletions core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,24 @@ impl<T: ?Sized> NonNull<T> {
}
}

/// Converts a reference to a `NonNull` pointer.
#[unstable(feature = "non_null_from_ref", issue = "130823")]
#[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")]
#[inline]
pub const fn from_ref(r: &T) -> Self {
// SAFETY: A reference cannot be null.
unsafe { NonNull { pointer: r as *const T } }
}

/// Converts a mutable reference to a `NonNull` pointer.
#[unstable(feature = "non_null_from_ref", issue = "130823")]
#[rustc_const_unstable(feature = "non_null_from_ref", issue = "130823")]
#[inline]
pub const fn from_mut(r: &mut T) -> Self {
// SAFETY: A mutable reference cannot be null.
unsafe { NonNull { pointer: r as *mut T } }
}

/// Performs the same functionality as [`std::ptr::from_raw_parts`], except that a
/// `NonNull` pointer is returned, as opposed to a raw `*const` pointer.
///
Expand Down Expand Up @@ -1749,9 +1767,8 @@ impl<T: ?Sized> From<&mut T> for NonNull<T> {
///
/// This conversion is safe and infallible since references cannot be null.
#[inline]
fn from(reference: &mut T) -> Self {
// SAFETY: A mutable reference cannot be null.
unsafe { NonNull { pointer: reference as *mut T } }
fn from(r: &mut T) -> Self {
NonNull::from_mut(r)
}
}

Expand All @@ -1761,8 +1778,7 @@ impl<T: ?Sized> From<&T> for NonNull<T> {
///
/// This conversion is safe and infallible since references cannot be null.
#[inline]
fn from(reference: &T) -> Self {
// SAFETY: A reference cannot be null.
unsafe { NonNull { pointer: reference as *const T } }
fn from(r: &T) -> Self {
NonNull::from_ref(r)
}
}

0 comments on commit 1e13241

Please sign in to comment.