diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 5b378de8bbddc..205f7f3696c97 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -102,7 +102,7 @@ pub(crate) fn expand_deriving_coerce_pointee( // # Validity assertion which will be checked later in `rustc_hir_analysis::coherence::builtins`. { let trait_path = - cx.path_all(span, true, path!(span, core::marker::CoercePointeeValidated), vec![]); + cx.path_all(span, true, path!(span, core::ops::CoercePointeeValidated), vec![]); let trait_ref = cx.trait_ref(trait_path); push(Annotatable::Item( cx.item( diff --git a/compiler/rustc_error_codes/src/error_codes/E0802.md b/compiler/rustc_error_codes/src/error_codes/E0802.md index 59061ff04359d..91befd88132fc 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0802.md +++ b/compiler/rustc_error_codes/src/error_codes/E0802.md @@ -7,7 +7,7 @@ The target data is not a `struct`. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] enum NotStruct<'a, T: ?Sized> { Variant(&'a T), @@ -19,7 +19,7 @@ in other words. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] struct NotTransparent<'a, #[pointee] T: ?Sized> { ptr: &'a T, @@ -30,7 +30,7 @@ The target data has no data field. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] struct NoField<'a, #[pointee] T: ?Sized> {} @@ -40,7 +40,7 @@ The target data is not generic over any data, or has no generic type parameter. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] struct NoGeneric<'a>(&'a u8); @@ -51,7 +51,7 @@ a pointee for coercion. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] struct AmbiguousPointee<'a, T1: ?Sized, T2: ?Sized> { @@ -64,7 +64,7 @@ pointees for coercion. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] struct TooManyPointees< @@ -78,7 +78,7 @@ The type parameter that is designated as a pointee is not marked `?Sized`. ```compile_fail,E0802 #![feature(coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] struct NoMaybeSized<'a, #[pointee] T> { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 4b767d8d62218..48e62873cbadd 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1132,212 +1132,5 @@ pub trait FnPtr: Copy + Clone { fn addr(self) -> *const (); } -/// Derive macro that makes a smart pointer usable with trait objects. -/// -/// # What this macro does -/// -/// This macro is intended to be used with user-defined pointer types, and makes it possible to -/// perform coercions on the pointee of the user-defined pointer. There are two aspects to this: -/// -/// ## Unsizing coercions of the pointee -/// -/// By using the macro, the following example will compile: -/// ``` -/// #![feature(derive_coerce_pointee)] -/// use std::marker::CoercePointee; -/// use std::ops::Deref; -/// -/// #[derive(CoercePointee)] -/// #[repr(transparent)] -/// struct MySmartPointer(Box); -/// -/// impl Deref for MySmartPointer { -/// type Target = T; -/// fn deref(&self) -> &T { -/// &self.0 -/// } -/// } -/// -/// trait MyTrait {} -/// -/// impl MyTrait for i32 {} -/// -/// fn main() { -/// let ptr: MySmartPointer = MySmartPointer(Box::new(4)); -/// -/// // This coercion would be an error without the derive. -/// let ptr: MySmartPointer = ptr; -/// } -/// ``` -/// Without the `#[derive(CoercePointee)]` macro, this example would fail with the following error: -/// ```text -/// error[E0308]: mismatched types -/// --> src/main.rs:11:44 -/// | -/// 11 | let ptr: MySmartPointer = ptr; -/// | --------------------------- ^^^ expected `MySmartPointer`, found `MySmartPointer` -/// | | -/// | expected due to this -/// | -/// = note: expected struct `MySmartPointer` -/// found struct `MySmartPointer` -/// = help: `i32` implements `MyTrait` so you could box the found value and coerce it to the trait object `Box`, you will have to change the expected type as well -/// ``` -/// -/// ## Dyn compatibility -/// -/// This macro allows you to dispatch on the user-defined pointer type. That is, traits using the -/// type as a receiver are dyn-compatible. For example, this compiles: -/// -/// ``` -/// #![feature(arbitrary_self_types, derive_coerce_pointee)] -/// use std::marker::CoercePointee; -/// use std::ops::Deref; -/// -/// #[derive(CoercePointee)] -/// #[repr(transparent)] -/// struct MySmartPointer(Box); -/// -/// impl Deref for MySmartPointer { -/// type Target = T; -/// fn deref(&self) -> &T { -/// &self.0 -/// } -/// } -/// -/// // You can always define this trait. (as long as you have #![feature(arbitrary_self_types)]) -/// trait MyTrait { -/// fn func(self: MySmartPointer); -/// } -/// -/// // But using `dyn MyTrait` requires #[derive(CoercePointee)]. -/// fn call_func(value: MySmartPointer) { -/// value.func(); -/// } -/// ``` -/// If you remove the `#[derive(CoercePointee)]` annotation from the struct, then the above example -/// will fail with this error message: -/// ```text -/// error[E0038]: the trait `MyTrait` is not dyn compatible -/// --> src/lib.rs:21:36 -/// | -/// 17 | fn func(self: MySmartPointer); -/// | -------------------- help: consider changing method `func`'s `self` parameter to be `&self`: `&Self` -/// ... -/// 21 | fn call_func(value: MySmartPointer) { -/// | ^^^^^^^^^^^ `MyTrait` is not dyn compatible -/// | -/// note: for a trait to be dyn compatible it needs to allow building a vtable -/// for more information, visit -/// --> src/lib.rs:17:19 -/// | -/// 16 | trait MyTrait { -/// | ------- this trait is not dyn compatible... -/// 17 | fn func(self: MySmartPointer); -/// | ^^^^^^^^^^^^^^^^^^^^ ...because method `func`'s `self` parameter cannot be dispatched on -/// ``` -/// -/// # Requirements for using the macro -/// -/// This macro can only be used if: -/// * The type is a `#[repr(transparent)]` struct. -/// * The type of its non-zero-sized field must either be a standard library pointer type -/// (reference, raw pointer, `NonNull`, `Box`, `Rc`, `Arc`, etc.) or another user-defined type -/// also using the `#[derive(CoercePointee)]` macro. -/// * Zero-sized fields must not mention any generic parameters unless the zero-sized field has -/// type [`PhantomData`]. -/// -/// ## Multiple type parameters -/// -/// If the type has multiple type parameters, then you must explicitly specify which one should be -/// used for dynamic dispatch. For example: -/// ``` -/// # #![feature(derive_coerce_pointee)] -/// # use std::marker::{CoercePointee, PhantomData}; -/// #[derive(CoercePointee)] -/// #[repr(transparent)] -/// struct MySmartPointer<#[pointee] T: ?Sized, U> { -/// ptr: Box, -/// _phantom: PhantomData, -/// } -/// ``` -/// Specifying `#[pointee]` when the struct has only one type parameter is allowed, but not required. -/// -/// # Examples -/// -/// A custom implementation of the `Rc` type: -/// ``` -/// #![feature(derive_coerce_pointee)] -/// use std::marker::CoercePointee; -/// use std::ops::Deref; -/// use std::ptr::NonNull; -/// -/// #[derive(CoercePointee)] -/// #[repr(transparent)] -/// pub struct Rc { -/// inner: NonNull>, -/// } -/// -/// struct RcInner { -/// refcount: usize, -/// value: T, -/// } -/// -/// impl Deref for Rc { -/// type Target = T; -/// fn deref(&self) -> &T { -/// let ptr = self.inner.as_ptr(); -/// unsafe { &(*ptr).value } -/// } -/// } -/// -/// impl Rc { -/// pub fn new(value: T) -> Self { -/// let inner = Box::new(RcInner { -/// refcount: 1, -/// value, -/// }); -/// Self { -/// inner: NonNull::from(Box::leak(inner)), -/// } -/// } -/// } -/// -/// impl Clone for Rc { -/// fn clone(&self) -> Self { -/// // A real implementation would handle overflow here. -/// unsafe { (*self.inner.as_ptr()).refcount += 1 }; -/// Self { inner: self.inner } -/// } -/// } -/// -/// impl Drop for Rc { -/// fn drop(&mut self) { -/// let ptr = self.inner.as_ptr(); -/// unsafe { (*ptr).refcount -= 1 }; -/// if unsafe { (*ptr).refcount } == 0 { -/// drop(unsafe { Box::from_raw(ptr) }); -/// } -/// } -/// } -/// ``` -#[rustc_builtin_macro(CoercePointee, attributes(pointee))] -#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)] -#[rustc_diagnostic_item = "CoercePointee"] #[unstable(feature = "derive_coerce_pointee", issue = "123430")] -pub macro CoercePointee($item:item) { - /* compiler built-in */ -} - -/// A trait that is implemented for ADTs with `derive(CoercePointee)` so that -/// the compiler can enforce the derive impls are valid post-expansion, since -/// the derive has stricter requirements than if the impls were written by hand. -/// -/// This trait is not intended to be implemented by users or used other than -/// validation, so it should never be stabilized. -#[lang = "coerce_pointee_validated"] -#[unstable(feature = "coerce_pointee_validated", issue = "none")] -#[doc(hidden)] -pub trait CoercePointeeValidated { - /* compiler built-in */ -} +pub use crate::ops::CoercePointee; diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index ab1ad407ee282..c8159c94947e9 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -199,6 +199,10 @@ pub use self::try_trait::Yeet; pub(crate) use self::try_trait::{ChangeOutputType, NeverShortCircuit}; #[unstable(feature = "try_trait_v2", issue = "84277", old_name = "try_trait")] pub use self::try_trait::{FromResidual, Try}; +#[unstable(feature = "derive_coerce_pointee", issue = "123430")] +pub use self::unsize::CoercePointee; +#[unstable(feature = "coerce_pointee_validated", issue = "none")] +pub use self::unsize::CoercePointeeValidated; #[unstable(feature = "coerce_unsized", issue = "18598")] pub use self::unsize::CoerceUnsized; #[unstable(feature = "dispatch_from_dyn", issue = "none")] diff --git a/library/core/src/ops/unsize.rs b/library/core/src/ops/unsize.rs index f0781ee01fd53..c5780d34fb7ce 100644 --- a/library/core/src/ops/unsize.rs +++ b/library/core/src/ops/unsize.rs @@ -132,3 +132,214 @@ impl, U: PointeeSized> DispatchFromDyn<*const U> for // *mut T -> *mut U #[unstable(feature = "dispatch_from_dyn", issue = "none")] impl, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {} + +/// Derive macro that makes a smart pointer usable with trait objects. +/// +/// # What this macro does +/// +/// This macro is intended to be used with user-defined pointer types, and makes it possible to +/// perform coercions on the pointee of the user-defined pointer. There are two aspects to this: +/// +/// ## Unsizing coercions of the pointee +/// +/// By using the macro, the following example will compile: +/// ``` +/// #![feature(derive_coerce_pointee)] +/// use std::ops::CoercePointee; +/// use std::ops::Deref; +/// +/// #[derive(CoercePointee)] +/// #[repr(transparent)] +/// struct MySmartPointer(Box); +/// +/// impl Deref for MySmartPointer { +/// type Target = T; +/// fn deref(&self) -> &T { +/// &self.0 +/// } +/// } +/// +/// trait MyTrait {} +/// +/// impl MyTrait for i32 {} +/// +/// fn main() { +/// let ptr: MySmartPointer = MySmartPointer(Box::new(4)); +/// +/// // This coercion would be an error without the derive. +/// let ptr: MySmartPointer = ptr; +/// } +/// ``` +/// Without the `#[derive(CoercePointee)]` macro, this example would fail with the following error: +/// ```text +/// error[E0308]: mismatched types +/// --> src/main.rs:11:44 +/// | +/// 11 | let ptr: MySmartPointer = ptr; +/// | --------------------------- ^^^ expected `MySmartPointer`, found `MySmartPointer` +/// | | +/// | expected due to this +/// | +/// = note: expected struct `MySmartPointer` +/// found struct `MySmartPointer` +/// = help: `i32` implements `MyTrait` so you could box the found value and coerce it to the trait object `Box`, you will have to change the expected type as well +/// ``` +/// +/// ## Dyn compatibility +/// +/// This macro allows you to dispatch on the user-defined pointer type. That is, traits using the +/// type as a receiver are dyn-compatible. For example, this compiles: +/// +/// ``` +/// #![feature(arbitrary_self_types, derive_coerce_pointee)] +/// use std::ops::CoercePointee; +/// use std::ops::Deref; +/// +/// #[derive(CoercePointee)] +/// #[repr(transparent)] +/// struct MySmartPointer(Box); +/// +/// impl Deref for MySmartPointer { +/// type Target = T; +/// fn deref(&self) -> &T { +/// &self.0 +/// } +/// } +/// +/// // You can always define this trait. (as long as you have #![feature(arbitrary_self_types)]) +/// trait MyTrait { +/// fn func(self: MySmartPointer); +/// } +/// +/// // But using `dyn MyTrait` requires #[derive(CoercePointee)]. +/// fn call_func(value: MySmartPointer) { +/// value.func(); +/// } +/// ``` +/// If you remove the `#[derive(CoercePointee)]` annotation from the struct, then the above example +/// will fail with this error message: +/// ```text +/// error[E0038]: the trait `MyTrait` is not dyn compatible +/// --> src/lib.rs:21:36 +/// | +/// 17 | fn func(self: MySmartPointer); +/// | -------------------- help: consider changing method `func`'s `self` parameter to be `&self`: `&Self` +/// ... +/// 21 | fn call_func(value: MySmartPointer) { +/// | ^^^^^^^^^^^ `MyTrait` is not dyn compatible +/// | +/// note: for a trait to be dyn compatible it needs to allow building a vtable +/// for more information, visit +/// --> src/lib.rs:17:19 +/// | +/// 16 | trait MyTrait { +/// | ------- this trait is not dyn compatible... +/// 17 | fn func(self: MySmartPointer); +/// | ^^^^^^^^^^^^^^^^^^^^ ...because method `func`'s `self` parameter cannot be dispatched on +/// ``` +/// +/// # Requirements for using the macro +/// +/// This macro can only be used if: +/// * The type is a `#[repr(transparent)]` struct. +/// * The type of its non-zero-sized field must either be a standard library pointer type +/// (reference, raw pointer, `NonNull`, `Box`, `Rc`, `Arc`, etc.) or another user-defined type +/// also using the `#[derive(CoercePointee)]` macro. +/// * Zero-sized fields must not mention any generic parameters unless the zero-sized field has +/// type [`PhantomData`](crate::marker::PhantomData). +/// +/// ## Multiple type parameters +/// +/// If the type has multiple type parameters, then you must explicitly specify which one should be +/// used for dynamic dispatch. For example: +/// ``` +/// # #![feature(derive_coerce_pointee)] +/// # use std::marker::PhantomData; +/// # use std::ops::CoercePointee; +/// #[derive(CoercePointee)] +/// #[repr(transparent)] +/// struct MySmartPointer<#[pointee] T: ?Sized, U> { +/// ptr: Box, +/// _phantom: PhantomData, +/// } +/// ``` +/// Specifying `#[pointee]` when the struct has only one type parameter is allowed, but not required. +/// +/// # Examples +/// +/// A custom implementation of the `Rc` type: +/// ``` +/// #![feature(derive_coerce_pointee)] +/// use std::ops::CoercePointee; +/// use std::ops::Deref; +/// use std::ptr::NonNull; +/// +/// #[derive(CoercePointee)] +/// #[repr(transparent)] +/// pub struct Rc { +/// inner: NonNull>, +/// } +/// +/// struct RcInner { +/// refcount: usize, +/// value: T, +/// } +/// +/// impl Deref for Rc { +/// type Target = T; +/// fn deref(&self) -> &T { +/// let ptr = self.inner.as_ptr(); +/// unsafe { &(*ptr).value } +/// } +/// } +/// +/// impl Rc { +/// pub fn new(value: T) -> Self { +/// let inner = Box::new(RcInner { +/// refcount: 1, +/// value, +/// }); +/// Self { +/// inner: NonNull::from(Box::leak(inner)), +/// } +/// } +/// } +/// +/// impl Clone for Rc { +/// fn clone(&self) -> Self { +/// // A real implementation would handle overflow here. +/// unsafe { (*self.inner.as_ptr()).refcount += 1 }; +/// Self { inner: self.inner } +/// } +/// } +/// +/// impl Drop for Rc { +/// fn drop(&mut self) { +/// let ptr = self.inner.as_ptr(); +/// unsafe { (*ptr).refcount -= 1 }; +/// if unsafe { (*ptr).refcount } == 0 { +/// drop(unsafe { Box::from_raw(ptr) }); +/// } +/// } +/// } +/// ``` +#[rustc_builtin_macro(CoercePointee, attributes(pointee))] +#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize, coerce_pointee_validated)] +#[rustc_diagnostic_item = "CoercePointee"] +#[unstable(feature = "derive_coerce_pointee", issue = "123430")] +pub macro CoercePointee($item:item) { + /* compiler built-in */ +} + +/// A trait that is implemented for ADTs with `derive(CoercePointee)` so that +/// the compiler can enforce the derive impls are valid post-expansion, since +/// the derive has stricter requirements than if the impls were written by hand. +/// +/// This trait is not intended to be implemented by users or used other than +/// validation, so it should never be stabilized. +#[lang = "coerce_pointee_validated"] +#[unstable(feature = "coerce_pointee_validated", issue = "none")] +#[doc(hidden)] +pub trait CoercePointeeValidated { + /* compiler built-in */ +} diff --git a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs index 0013c2a25679a..663c808fb9e0d 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs @@ -661,7 +661,7 @@ fn coerce_pointee_expansion() { r#" //- minicore: coerce_pointee -use core::marker::CoercePointee; +use core::ops::CoercePointee; pub trait Trait {} @@ -672,7 +672,7 @@ where U: Trait + ToString;"#, expect![[r#" -use core::marker::CoercePointee; +use core::ops::CoercePointee; pub trait Trait {} @@ -692,7 +692,7 @@ fn coerce_pointee_errors() { r#" //- minicore: coerce_pointee -use core::marker::CoercePointee; +use core::ops::CoercePointee; #[derive(CoercePointee)] enum Enum {} diff --git a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs index 696928b522f94..391309e800c69 100644 --- a/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs +++ b/src/tools/rust-analyzer/crates/test-utils/src/minicore.rs @@ -189,14 +189,6 @@ pub mod marker { type Discriminant; } // endregion:discriminant - - // region:coerce_pointee - #[rustc_builtin_macro(CoercePointee, attributes(pointee))] - #[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)] - pub macro CoercePointee($item:item) { - /* compiler built-in */ - } - // endregion:coerce_pointee } // region:default @@ -1102,6 +1094,14 @@ pub mod ops { } pub use self::dispatch_from_dyn::DispatchFromDyn; // endregion:dispatch_from_dyn + + // region:coerce_pointee + #[rustc_builtin_macro(CoercePointee, attributes(pointee))] + #[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)] + pub macro CoercePointee($item:item) { + /* compiler built-in */ + } + // endregion:coerce_pointee } // region:eq diff --git a/tests/ui/deriving/built-in-proc-macro-scope.rs b/tests/ui/deriving/built-in-proc-macro-scope.rs index 69128a08b9978..5b78a2b3593b8 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.rs +++ b/tests/ui/deriving/built-in-proc-macro-scope.rs @@ -10,7 +10,7 @@ extern crate another_proc_macro; use another_proc_macro::{AnotherMacro, pointee}; -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr<'a, #[pointee] T: ?Sized> { data: &'a mut T, diff --git a/tests/ui/deriving/built-in-proc-macro-scope.stdout b/tests/ui/deriving/built-in-proc-macro-scope.stdout index 4fbce5edb8194..e05919d3e9df4 100644 --- a/tests/ui/deriving/built-in-proc-macro-scope.stdout +++ b/tests/ui/deriving/built-in-proc-macro-scope.stdout @@ -21,7 +21,7 @@ pub struct Ptr<'a, #[pointee] T: ?Sized> { data: &'a mut T, } #[automatically_derived] -impl<'a, T: ?Sized> ::core::marker::CoercePointeeValidated for Ptr<'a, T> { } +impl<'a, T: ?Sized> ::core::ops::CoercePointeeValidated for Ptr<'a, T> { } #[automatically_derived] impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> ::core::ops::DispatchFromDyn> for Ptr<'a, T> { diff --git a/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs b/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs index a1aabf1cb527d..09b37d97ba115 100644 --- a/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs +++ b/tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs @@ -2,7 +2,7 @@ #![feature(derive_coerce_pointee)] -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> { data: &'a mut T, @@ -13,7 +13,7 @@ pub trait OnDrop { fn on_drop(&mut self); } -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr2<'a, #[pointee] T: ?Sized, X> where @@ -25,7 +25,7 @@ where pub trait MyTrait {} -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr3<'a, #[pointee] T: ?Sized, X> where @@ -35,14 +35,14 @@ where x: core::marker::PhantomData, } -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr4<'a, #[pointee] T: MyTrait + ?Sized, X> { data: &'a mut T, x: core::marker::PhantomData, } -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr5<'a, #[pointee] T: ?Sized, X> where @@ -56,7 +56,7 @@ where pub struct Ptr5Companion(core::marker::PhantomData); pub struct Ptr5Companion2; -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait = (), const PARAM: usize = 0> { data: &'a mut T, @@ -65,7 +65,7 @@ pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait = (), const PARAM: usize // a reduced example from https://lore.kernel.org/all/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com/ #[repr(transparent)] -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] pub struct ListArc<#[pointee] T, const ID: u64 = 0> where T: ListArcSafe + ?Sized, diff --git a/tests/ui/deriving/deriving-coerce-pointee-expanded.rs b/tests/ui/deriving/deriving-coerce-pointee-expanded.rs index 9394ae4efe5ae..1b24b3c112754 100644 --- a/tests/ui/deriving/deriving-coerce-pointee-expanded.rs +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.rs @@ -2,7 +2,7 @@ //@ compile-flags: -Zunpretty=expanded //@ edition: 2015 #![feature(derive_coerce_pointee)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; pub trait MyTrait {} @@ -12,7 +12,7 @@ struct MyPointer<'a, #[pointee] T: ?Sized> { ptr: &'a T, } -#[derive(core::marker::CoercePointee)] +#[derive(core::ops::CoercePointee)] #[repr(transparent)] pub struct MyPointer2<'a, Y, Z: MyTrait, #[pointee] T: ?Sized + MyTrait, X: MyTrait = ()> where diff --git a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout index 89300a5c6d0ca..178d3e888c408 100644 --- a/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout +++ b/tests/ui/deriving/deriving-coerce-pointee-expanded.stdout @@ -8,7 +8,7 @@ extern crate std; #[prelude_import] use ::std::prelude::rust_2015::*; -use std::marker::CoercePointee; +use std::ops::CoercePointee; pub trait MyTrait {} @@ -17,8 +17,7 @@ struct MyPointer<'a, #[pointee] T: ?Sized> { ptr: &'a T, } #[automatically_derived] -impl<'a, T: ?Sized> ::core::marker::CoercePointeeValidated for - MyPointer<'a, T> { +impl<'a, T: ?Sized> ::core::ops::CoercePointeeValidated for MyPointer<'a, T> { } #[automatically_derived] impl<'a, T: ?Sized + ::core::marker::Unsize<__S>, __S: ?Sized> @@ -37,8 +36,8 @@ pub struct MyPointer2<'a, Y, Z: MyTrait, #[pointee] T: ?Sized + MyTrait, } #[automatically_derived] impl<'a, Y, Z: MyTrait, T: ?Sized + MyTrait, X: MyTrait> - ::core::marker::CoercePointeeValidated for MyPointer2<'a, Y, Z, T, X> - where Y: MyTrait { + ::core::ops::CoercePointeeValidated for MyPointer2<'a, Y, Z, T, X> where + Y: MyTrait { } #[automatically_derived] impl<'a, Y, Z: MyTrait + MyTrait<__S>, T: ?Sized + MyTrait + @@ -58,7 +57,7 @@ struct MyPointerWithoutPointee<'a, T: ?Sized> { ptr: &'a T, } #[automatically_derived] -impl<'a, T: ?Sized> ::core::marker::CoercePointeeValidated for +impl<'a, T: ?Sized> ::core::ops::CoercePointeeValidated for MyPointerWithoutPointee<'a, T> { } #[automatically_derived] diff --git a/tests/ui/deriving/deriving-coerce-pointee-neg.rs b/tests/ui/deriving/deriving-coerce-pointee-neg.rs index 2713366945e9a..f55a650d482c5 100644 --- a/tests/ui/deriving/deriving-coerce-pointee-neg.rs +++ b/tests/ui/deriving/deriving-coerce-pointee-neg.rs @@ -4,7 +4,7 @@ extern crate core; extern crate malicious_macro; -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] //~^ ERROR: `CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]` diff --git a/tests/ui/deriving/deriving-coerce-pointee.rs b/tests/ui/deriving/deriving-coerce-pointee.rs index 26762e4d0face..5443183050cd5 100644 --- a/tests/ui/deriving/deriving-coerce-pointee.rs +++ b/tests/ui/deriving/deriving-coerce-pointee.rs @@ -1,7 +1,7 @@ //@ run-pass #![feature(derive_coerce_pointee, arbitrary_self_types)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; #[derive(CoercePointee)] #[repr(transparent)] diff --git a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs index d730849dcf6aa..385f25716b96f 100644 --- a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs +++ b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs @@ -1,4 +1,4 @@ -use std::marker::CoercePointee; //~ ERROR use of unstable library feature `derive_coerce_pointee` +use std::ops::CoercePointee; //~ ERROR use of unstable library feature `derive_coerce_pointee` #[derive(CoercePointee)] //~ ERROR use of unstable library feature `derive_coerce_pointee` #[repr(transparent)] diff --git a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr index 19babe149d9a4..a5a1774b95e88 100644 --- a/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr +++ b/tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr @@ -11,8 +11,8 @@ LL | #[derive(CoercePointee)] error[E0658]: use of unstable library feature `derive_coerce_pointee` --> $DIR/feature-gate-derive-coerce-pointee.rs:1:5 | -LL | use std::marker::CoercePointee; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | use std::ops::CoercePointee; + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #123430 for more information = help: add `#![feature(derive_coerce_pointee)]` to the crate attributes to enable diff --git a/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs b/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs index f9e346ea11e21..2e136bbb9211f 100644 --- a/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs +++ b/tests/ui/self/arbitrary_self_types_dispatch_to_vtable.rs @@ -3,7 +3,7 @@ #![feature(derive_coerce_pointee)] #![feature(arbitrary_self_types)] -use std::marker::CoercePointee; +use std::ops::CoercePointee; use std::ops::Receiver; // `CoercePointee` isn't needed here, it's just a simpler diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs index 55c070eb03682..41c8a8e2e6056 100644 --- a/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs +++ b/tests/ui/self/dyn-dispatch-requires-supertrait-norm.rs @@ -4,7 +4,7 @@ #![feature(arbitrary_self_types)] use std::ops::Deref; -use std::marker::CoercePointee; +use std::ops::CoercePointee; use std::sync::Arc; trait MyTrait {} diff --git a/tests/ui/self/dyn-dispatch-requires-supertrait.rs b/tests/ui/self/dyn-dispatch-requires-supertrait.rs index f2661c406fef0..6ef5c03b8cb85 100644 --- a/tests/ui/self/dyn-dispatch-requires-supertrait.rs +++ b/tests/ui/self/dyn-dispatch-requires-supertrait.rs @@ -4,7 +4,7 @@ #![feature(arbitrary_self_types)] use std::ops::Deref; -use std::marker::CoercePointee; +use std::ops::CoercePointee; use std::sync::Arc; trait MyTrait {}