From a349b552e3dad62c6de437537fca19961ef95993 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 19 Jan 2026 17:36:08 +0000 Subject: [PATCH 1/2] build: simplify use of nightly features Instead of check if a feature is already stable, simply enable them and allow the warning if the feature is already stable. This avoids the need of the hardcoding whether a feature has been stabilized at a given version. Signed-off-by: Gary Guo --- Cargo.toml | 1 + build.rs | 21 ++++++++--------- examples/linked_list.rs | 2 +- examples/mutex.rs | 2 +- examples/pthread_mutex.rs | 2 +- examples/static_init.rs | 2 +- internal/Cargo.toml | 1 + internal/build.rs | 14 ++++++----- internal/src/lib.rs | 2 +- src/lib.rs | 7 ++---- tests/alloc_fail.rs | 2 +- tests/cfgs.rs | 2 +- tests/const-generic-default.rs | 2 +- tests/init-scope.rs | 2 +- tests/many_generics.rs | 2 +- tests/ring_buf.rs | 2 +- tests/ui.rs | 2 +- .../pin_data/no_pin_on_phantompinned.stderr | 23 ------------------- tests/ui/expand/many_generics.expanded.rs | 1 - tests/zeroing.rs | 2 +- 20 files changed, 35 insertions(+), 59 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cee2a4d1..e189b6d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ macrotest = "1.0" prettyplease = { version = "0.2.37", features = ["verbatim"] } [lints.rust] +stable_features = "allow" non_ascii_idents = "deny" unexpected_cfgs = { level = "warn", check-cfg = [ 'cfg(UI_TESTS)', diff --git a/build.rs b/build.rs index fddbb5dc..34d262b0 100644 --- a/build.rs +++ b/build.rs @@ -1,18 +1,17 @@ -use rustc_version::{version, Version}; +use rustc_version::{version_meta, Channel, Version}; fn main() { - println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)"); - println!("cargo::rustc-check-cfg=cfg(RUSTC_NEW_UNINIT_IS_STABLE)"); + println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)"); println!("cargo::rustc-check-cfg=cfg(CONFIG_RUSTC_HAS_UNSAFE_PINNED)"); - if version().unwrap() >= Version::parse("1.81.0").unwrap() - || version().unwrap() >= Version::parse("1.81.0-nightly").unwrap() - { - println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE"); - } - if version().unwrap() >= Version::parse("1.82.0").unwrap() { - println!("cargo:rustc-cfg=RUSTC_NEW_UNINIT_IS_STABLE"); + + let meta = version_meta().unwrap(); + + let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok(); + if use_feature { + println!("cargo:rustc-cfg=RUSTC_USE_FEATURE"); } - if version().unwrap() >= Version::parse("1.89.0-nightly").unwrap() { + + if meta.semver >= Version::parse("1.89.0-nightly").unwrap() && use_feature { println!("cargo:rustc-cfg=CONFIG_RUSTC_HAS_UNSAFE_PINNED"); } } diff --git a/examples/linked_list.rs b/examples/linked_list.rs index 8445a589..d40b5516 100644 --- a/examples/linked_list.rs +++ b/examples/linked_list.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use core::{ cell::Cell, diff --git a/examples/mutex.rs b/examples/mutex.rs index 9f295226..6b4d4920 100644 --- a/examples/mutex.rs +++ b/examples/mutex.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(clippy::missing_safety_doc)] use core::{ diff --git a/examples/pthread_mutex.rs b/examples/pthread_mutex.rs index 4e082ec7..d5bfd493 100644 --- a/examples/pthread_mutex.rs +++ b/examples/pthread_mutex.rs @@ -3,7 +3,7 @@ // inspired by #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[cfg(not(windows))] mod pthread_mtx { diff --git a/examples/static_init.rs b/examples/static_init.rs index 0e165daa..30b6cb43 100644 --- a/examples/static_init.rs +++ b/examples/static_init.rs @@ -2,7 +2,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(unused_imports)] use core::{ diff --git a/internal/Cargo.toml b/internal/Cargo.toml index d3af5351..c8810106 100644 --- a/internal/Cargo.toml +++ b/internal/Cargo.toml @@ -21,4 +21,5 @@ syn = { version = "2.0.86", features = ["full", "parsing", "visit-mut"] } rustc_version = "0.4" [lints.rust] +stable_features = "allow" unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kernel)'] } diff --git a/internal/build.rs b/internal/build.rs index 2fdb56a9..f254d07f 100644 --- a/internal/build.rs +++ b/internal/build.rs @@ -1,10 +1,12 @@ -use rustc_version::{version, Version}; +use rustc_version::{version_meta, Channel}; fn main() { - println!("cargo::rustc-check-cfg=cfg(RUSTC_LINT_REASONS_IS_STABLE)"); - if version().unwrap() >= Version::parse("1.81.0").unwrap() - || version().unwrap() >= Version::parse("1.81.0-nightly").unwrap() - { - println!("cargo:rustc-cfg=RUSTC_LINT_REASONS_IS_STABLE"); + println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)"); + + let meta = version_meta().unwrap(); + + let use_feature = meta.channel == Channel::Nightly || std::env::var("RUSTC_BOOTSTRAP").is_ok(); + if use_feature { + println!("cargo:rustc-cfg=RUSTC_USE_FEATURE"); } } diff --git a/internal/src/lib.rs b/internal/src/lib.rs index 08372c8f..08ca5c2f 100644 --- a/internal/src/lib.rs +++ b/internal/src/lib.rs @@ -6,7 +6,7 @@ //! `pin-init` proc macros. -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] // Documentation is done in the pin-init crate instead. #![allow(missing_docs)] diff --git a/src/lib.rs b/src/lib.rs index 49945fc0..260d1635 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -264,12 +264,9 @@ //! [`impl Init`]: crate::Init //! [Rust-for-Linux]: https://rust-for-linux.com/ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![cfg_attr( - all( - any(feature = "alloc", feature = "std"), - not(RUSTC_NEW_UNINIT_IS_STABLE) - ), + all(any(feature = "alloc", feature = "std"), RUSTC_USE_FEATURE), feature(new_uninit) )] #![forbid(missing_docs, unsafe_op_in_unsafe_fn)] diff --git a/tests/alloc_fail.rs b/tests/alloc_fail.rs index bc7937bf..2a058e8e 100644 --- a/tests/alloc_fail.rs +++ b/tests/alloc_fail.rs @@ -1,5 +1,5 @@ #![cfg_attr(feature = "alloc", feature(allocator_api))] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[test] #[cfg(feature = "alloc")] diff --git a/tests/cfgs.rs b/tests/cfgs.rs index a28d0db4..8350f607 100644 --- a/tests/cfgs.rs +++ b/tests/cfgs.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::{pin_data, pin_init, PinInit}; diff --git a/tests/const-generic-default.rs b/tests/const-generic-default.rs index 7660272c..0c234296 100644 --- a/tests/const-generic-default.rs +++ b/tests/const-generic-default.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::*; diff --git a/tests/init-scope.rs b/tests/init-scope.rs index 2ea700ab..0a94cf15 100644 --- a/tests/init-scope.rs +++ b/tests/init-scope.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use pin_init::*; diff --git a/tests/many_generics.rs b/tests/many_generics.rs index d45ac287..0c1d9bdf 100644 --- a/tests/many_generics.rs +++ b/tests/many_generics.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![allow(dead_code)] use core::{marker::PhantomPinned, pin::Pin}; diff --git a/tests/ring_buf.rs b/tests/ring_buf.rs index 9029f511..c1aad66e 100644 --- a/tests/ring_buf.rs +++ b/tests/ring_buf.rs @@ -1,5 +1,5 @@ #![allow(clippy::undocumented_unsafe_blocks)] -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #![cfg_attr(feature = "alloc", feature(allocator_api))] #[cfg(all(not(feature = "std"), feature = "alloc"))] diff --git a/tests/ui.rs b/tests/ui.rs index 4eb03f85..f20e0bd6 100644 --- a/tests/ui.rs +++ b/tests/ui.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] #[test] #[cfg_attr(not(UI_TESTS), ignore)] diff --git a/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr b/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr index 63d59d69..fedd62ab 100644 --- a/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr +++ b/tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.stderr @@ -21,26 +21,3 @@ error: The field `pin4` of type `PhantomPinned` only has an effect if it has the | 9 | pin4: ::core::marker::PhantomPinned, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0425]: cannot find type `PhantomPinned` in this scope - --> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:6:11 - | -6 | pin1: PhantomPinned, - | ^^^^^^^^^^^^^ not found in this scope - | -help: consider importing this struct - | -1 + use std::marker::PhantomPinned; - | - -error[E0433]: failed to resolve: use of unresolved module or unlinked crate `marker` - --> tests/ui/compile-fail/pin_data/no_pin_on_phantompinned.rs:7:11 - | -7 | pin2: marker::PhantomPinned, - | ^^^^^^ use of unresolved module or unlinked crate `marker` - | - = help: if you wanted to use a crate named `marker`, use `cargo add marker` to add it to your `Cargo.toml` -help: consider importing this module - | -1 + use std::marker; - | diff --git a/tests/ui/expand/many_generics.expanded.rs b/tests/ui/expand/many_generics.expanded.rs index 44a4efa1..35f99102 100644 --- a/tests/ui/expand/many_generics.expanded.rs +++ b/tests/ui/expand/many_generics.expanded.rs @@ -1,4 +1,3 @@ -#![feature(lint_reasons)] #![allow(dead_code)] use core::{marker::PhantomPinned, pin::Pin}; use pin_init::*; diff --git a/tests/zeroing.rs b/tests/zeroing.rs index 6d10ad77..3f013c3a 100644 --- a/tests/zeroing.rs +++ b/tests/zeroing.rs @@ -1,4 +1,4 @@ -#![cfg_attr(not(RUSTC_LINT_REASONS_IS_STABLE), feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] use core::{marker::PhantomPinned, ptr::addr_of_mut}; From eb3dec3c83efccd728b1c14c2fbaf2ba394b91d3 Mon Sep 17 00:00:00 2001 From: Antonio Hickey Date: Sun, 27 Apr 2025 22:34:28 -0400 Subject: [PATCH 2/2] refactor to use `&raw mut` Replacing all occurrences of `addr_of_mut!(place)` with `&raw mut place`. This will allow us to reduce macro complexity, and improve consistency with existing reference syntax as `&raw mut` is similar to `&mut` making it fit more naturally with other existing code. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/linux/issues/1148 Signed-off-by: Antonio Hickey --- README.md | 3 +-- build.rs | 4 ++++ examples/big_struct_in_place.rs | 2 ++ examples/linked_list.rs | 1 + examples/mutex.rs | 1 + examples/pthread_mutex.rs | 1 + examples/static_init.rs | 1 + internal/src/init.rs | 8 ++++---- src/lib.rs | 8 ++++---- tests/cfgs.rs | 1 + tests/const-generic-default.rs | 1 + tests/init-scope.rs | 1 + tests/ring_buf.rs | 15 +++++---------- tests/underscore.rs | 2 ++ tests/zeroing.rs | 5 +++-- 15 files changed, 32 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 6cee6ab1..9095d666 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,6 @@ actually does the initialization in the correct way. Here are the things to look ```rust use pin_init::{pin_data, pinned_drop, PinInit, PinnedDrop, pin_init_from_closure}; use core::{ - ptr::addr_of_mut, marker::PhantomPinned, cell::UnsafeCell, pin::Pin, @@ -199,7 +198,7 @@ impl RawFoo { unsafe { pin_init_from_closure(move |slot: *mut Self| { // `slot` contains uninit memory, avoid creating a reference. - let foo = addr_of_mut!((*slot).foo); + let foo = &raw mut (*slot).foo; let foo = UnsafeCell::raw_get(foo).cast::(); // Initialize the `foo` diff --git a/build.rs b/build.rs index 34d262b0..a25be0f1 100644 --- a/build.rs +++ b/build.rs @@ -3,6 +3,7 @@ use rustc_version::{version_meta, Channel, Version}; fn main() { println!("cargo::rustc-check-cfg=cfg(RUSTC_USE_FEATURE)"); println!("cargo::rustc-check-cfg=cfg(CONFIG_RUSTC_HAS_UNSAFE_PINNED)"); + println!("cargo:rustc-check-cfg=cfg(RUSTC_RAW_REF_OP_IS_STABLE)"); let meta = version_meta().unwrap(); @@ -14,4 +15,7 @@ fn main() { if meta.semver >= Version::parse("1.89.0-nightly").unwrap() && use_feature { println!("cargo:rustc-cfg=CONFIG_RUSTC_HAS_UNSAFE_PINNED"); } + if meta.semver >= Version::parse("1.82.0").unwrap() && use_feature { + println!("cargo:rustc-cfg=RUSTC_RAW_REF_OP_IS_STABLE"); + } } diff --git a/examples/big_struct_in_place.rs b/examples/big_struct_in_place.rs index c0513992..341e6df1 100644 --- a/examples/big_struct_in_place.rs +++ b/examples/big_struct_in_place.rs @@ -1,5 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT +#![cfg_attr(not(RUSTC_RAW_REF_OP_IS_STABLE), feature(raw_ref_op))] + use pin_init::*; // Struct with size over 1GiB diff --git a/examples/linked_list.rs b/examples/linked_list.rs index d40b5516..ed97089d 100644 --- a/examples/linked_list.rs +++ b/examples/linked_list.rs @@ -3,6 +3,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] use core::{ cell::Cell, diff --git a/examples/mutex.rs b/examples/mutex.rs index 6b4d4920..6d963ce8 100644 --- a/examples/mutex.rs +++ b/examples/mutex.rs @@ -3,6 +3,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] #![allow(clippy::missing_safety_doc)] use core::{ diff --git a/examples/pthread_mutex.rs b/examples/pthread_mutex.rs index d5bfd493..41aab6cc 100644 --- a/examples/pthread_mutex.rs +++ b/examples/pthread_mutex.rs @@ -4,6 +4,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] #[cfg(not(windows))] mod pthread_mtx { diff --git a/examples/static_init.rs b/examples/static_init.rs index 30b6cb43..635b6560 100644 --- a/examples/static_init.rs +++ b/examples/static_init.rs @@ -3,6 +3,7 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] #![allow(unused_imports)] use core::{ diff --git a/internal/src/init.rs b/internal/src/init.rs index 42936f91..dc73cf7b 100644 --- a/internal/src/init.rs +++ b/internal/src/init.rs @@ -284,7 +284,7 @@ fn init_fields( { #value_prep // SAFETY: TODO - unsafe { #write(::core::ptr::addr_of_mut!((*#slot).#ident), #value_ident) }; + unsafe { #write(&raw mut (*#slot).#ident, #value_ident) }; } #accessor } @@ -301,7 +301,7 @@ fn init_fields( // return when an error/panic occurs. // - We also use `#data` to require the correct trait (`Init` or `PinInit`) // for `#ident`. - unsafe { #data.#ident(::core::ptr::addr_of_mut!((*#slot).#ident), #init)? }; + unsafe { #data.#ident(&raw mut (*#slot).#ident, #init)? }; }, quote! { // SAFETY: TODO @@ -316,7 +316,7 @@ fn init_fields( unsafe { ::pin_init::Init::__init( #init, - ::core::ptr::addr_of_mut!((*#slot).#ident), + &raw mut (*#slot).#ident, )? }; }, @@ -361,7 +361,7 @@ fn init_fields( // SAFETY: We forget the guard later when initialization has succeeded. let #guard = unsafe { ::pin_init::__internal::DropGuard::new( - ::core::ptr::addr_of_mut!((*slot).#ident) + &raw mut (*slot).#ident ) }; }); diff --git a/src/lib.rs b/src/lib.rs index 260d1635..38e3cd12 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -172,7 +172,6 @@ //! # #![feature(extern_types)] //! use pin_init::{pin_data, pinned_drop, PinInit, PinnedDrop, pin_init_from_closure}; //! use core::{ -//! ptr::addr_of_mut, //! marker::PhantomPinned, //! cell::UnsafeCell, //! pin::Pin, @@ -211,7 +210,7 @@ //! unsafe { //! pin_init_from_closure(move |slot: *mut Self| { //! // `slot` contains uninit memory, avoid creating a reference. -//! let foo = addr_of_mut!((*slot).foo); +//! let foo = &raw mut (*slot).foo; //! let foo = UnsafeCell::raw_get(foo).cast::(); //! //! // Initialize the `foo` @@ -265,6 +264,7 @@ //! [Rust-for-Linux]: https://rust-for-linux.com/ #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] #![cfg_attr( all(any(feature = "alloc", feature = "std"), RUSTC_USE_FEATURE), feature(new_uninit) @@ -752,7 +752,7 @@ macro_rules! stack_try_pin_init { /// /// ```rust /// # use pin_init::*; -/// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; +/// # use core::marker::PhantomPinned; /// #[pin_data] /// #[derive(Zeroable)] /// struct Buf { @@ -766,7 +766,7 @@ macro_rules! stack_try_pin_init { /// let init = pin_init!(&this in Buf { /// buf: [0; 64], /// // SAFETY: TODO. -/// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() }, +/// ptr: unsafe { (&raw mut (*this.as_ptr()).buf).cast() }, /// pin: PhantomPinned, /// }); /// let init = pin_init!(Buf { diff --git a/tests/cfgs.rs b/tests/cfgs.rs index 8350f607..48f6baf1 100644 --- a/tests/cfgs.rs +++ b/tests/cfgs.rs @@ -1,4 +1,5 @@ #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] use pin_init::{pin_data, pin_init, PinInit}; diff --git a/tests/const-generic-default.rs b/tests/const-generic-default.rs index 0c234296..426edb36 100644 --- a/tests/const-generic-default.rs +++ b/tests/const-generic-default.rs @@ -1,4 +1,5 @@ #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] use pin_init::*; diff --git a/tests/init-scope.rs b/tests/init-scope.rs index 0a94cf15..276677f0 100644 --- a/tests/init-scope.rs +++ b/tests/init-scope.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] use pin_init::*; diff --git a/tests/ring_buf.rs b/tests/ring_buf.rs index c1aad66e..b5adde3d 100644 --- a/tests/ring_buf.rs +++ b/tests/ring_buf.rs @@ -1,16 +1,11 @@ #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] #![cfg_attr(feature = "alloc", feature(allocator_api))] #[cfg(all(not(feature = "std"), feature = "alloc"))] use alloc::sync::Arc; -use core::{ - convert::Infallible, - marker::PhantomPinned, - mem::MaybeUninit, - pin::Pin, - ptr::{self, addr_of_mut}, -}; +use core::{convert::Infallible, marker::PhantomPinned, mem::MaybeUninit, pin::Pin, ptr}; use pin_init::*; #[cfg(feature = "std")] use std::sync::Arc; @@ -50,8 +45,8 @@ impl RingBuffer { // SAFETY: The elements of the array can be uninitialized. buffer <- unsafe { init_from_closure(|_| Ok::<_, Infallible>(())) }, // SAFETY: `this` is a valid pointer. - head: unsafe { addr_of_mut!((*this.as_ptr()).buffer).cast::() }, - tail: unsafe { addr_of_mut!((*this.as_ptr()).buffer).cast::() }, + head: unsafe { (&raw mut (*this.as_ptr()).buffer).cast::() }, + tail: unsafe { (&raw mut (*this.as_ptr()).buffer).cast::() }, _pin: PhantomPinned, }) } @@ -112,7 +107,7 @@ impl RingBuffer { unsafe fn advance(&mut self, ptr: *mut T) -> *mut T { // SAFETY: ptr's offset from buffer is < SIZE let ptr = unsafe { ptr.add(1) }; - let origin: *mut _ = addr_of_mut!(self.buffer); + let origin: *mut _ = &raw mut (self.buffer); let origin = origin.cast::(); let offset = unsafe { ptr.offset_from(origin) }; if offset >= SIZE as isize { diff --git a/tests/underscore.rs b/tests/underscore.rs index a55a238a..96ffeb82 100644 --- a/tests/underscore.rs +++ b/tests/underscore.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(RUSTC_RAW_REF_OP_IS_STABLE), feature(raw_ref_op))] + use pin_init::{init, Init}; pub struct Foo { diff --git a/tests/zeroing.rs b/tests/zeroing.rs index 3f013c3a..e2f95822 100644 --- a/tests/zeroing.rs +++ b/tests/zeroing.rs @@ -1,6 +1,7 @@ #![cfg_attr(RUSTC_USE_FEATURE, feature(lint_reasons))] +#![cfg_attr(RUSTC_USE_FEATURE, feature(raw_ref_op))] -use core::{marker::PhantomPinned, ptr::addr_of_mut}; +use std::marker::PhantomPinned; use pin_init::*; @@ -22,7 +23,7 @@ impl Foo { marks: { let ptr = this.as_ptr(); // SAFETY: project from the NonNull to the buf field - let ptr = unsafe { addr_of_mut!((*ptr).buf) }.cast::(); + let ptr = unsafe { &raw mut (*ptr).buf }.cast::(); [ptr; MARKS]}, ..Zeroable::init_zeroed() })