Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 208e5bb

Browse files
committedDec 4, 2024
stabilize derive(CoercePointee)
1 parent 490b2cc commit 208e5bb

6 files changed

+39
-39
lines changed
 

‎library/core/src/marker.rs

+36-3
Original file line numberDiff line numberDiff line change
@@ -1075,11 +1075,44 @@ pub trait FnPtr: Copy + Clone {
10751075
fn addr(self) -> *const ();
10761076
}
10771077

1078-
/// Derive macro generating impls of traits related to smart pointers.
1078+
/// Derive macro generating implementations of traits
1079+
/// in relation to coercion of types to unsized or dynamic-sized types
1080+
/// with dynamic dispatching.
1081+
///
1082+
/// This macro will enable the target structure to equip with capabilities
1083+
/// to weaken a concrete type in its generic parameters to its unsized
1084+
/// variants.
1085+
/// For instance, it admits coercion of a `[T; SIZE]` to `[T]` where `SIZE`
1086+
/// is a constant; and coercion of a concrete type `T` to `dyn Trait` when
1087+
/// `T` implements an object-safe trait `Trait`.
1088+
/// See the [DST coercion RFC][RFC982] and
1089+
/// [the nomicon entry on coercion][nomicon-coerce] on the topics of this coercion.
1090+
///
1091+
/// The macro would choose a generic parameter labelled by a `#[pointee]` attribute first,
1092+
/// and resorts to the first type parameter from the left of
1093+
/// the list of generics as the target parameter that
1094+
/// the weakening is allowed.
1095+
///
1096+
/// # Pre-requisites
1097+
/// Applying this macro demands the following pre-requisites on the target item.
1098+
/// - The target item is a `struct`.
1099+
/// - The `struct` has a transparent data layout via `#[repr(transparent)]`.
1100+
/// - The `struct` has at least one data field.
1101+
/// - The `struct` has at least one generic type parameter.
1102+
/// - The `struct` has at most one generic type parameter
1103+
/// with macro attribute `#[pointee]` attached.
1104+
/// - The only data field of this `struct` has a type that also implements the same
1105+
/// coercion protocol.
1106+
/// For instance, this type can be [`alloc::box::Box`] or [`alloc::rc::Rc`], or
1107+
/// another custom type with the [`CoercePointee`] derived.
1108+
///
1109+
/// For more information, please refer to [the feature RFC][RFC3621].
1110+
/// [nomicon-coerce]: ../../nomicon/coercions.html
1111+
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
1112+
/// [RFC3621]: https://github.com/rust-lang/rfcs/pull/3621
10791113
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
10801114
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
1081-
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
1082-
#[cfg(not(bootstrap))]
1115+
#[stable(feature = "derive_coerce_pointee", since = "CURRENT_RUSTC_VERSION")]
10831116
pub macro CoercePointee($item:item) {
10841117
/* compiler built-in */
10851118
}

‎tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(derive_coerce_pointee)]
4-
53
#[derive(core::marker::CoercePointee)]
64
#[repr(transparent)]
75
pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> {

‎tests/ui/deriving/deriving-coerce-pointee-neg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(derive_coerce_pointee, arbitrary_self_types)]
1+
#![feature(arbitrary_self_types)]
22

33
extern crate core;
44
use std::marker::CoercePointee;

‎tests/ui/deriving/deriving-coerce-pointee.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ run-pass
2-
#![feature(derive_coerce_pointee, arbitrary_self_types)]
2+
3+
#![feature(arbitrary_self_types)]
34

45
use std::marker::CoercePointee;
56

‎tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs

-9
This file was deleted.

‎tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr

-23
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.