Skip to content

Commit

Permalink
stabilize derive(CoercePointee)
Browse files Browse the repository at this point in the history
  • Loading branch information
dingxiangfei2009 committed Dec 3, 2024
1 parent 490b2cc commit 8baca16
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
33 changes: 30 additions & 3 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,38 @@ pub trait FnPtr: Copy + Clone {
fn addr(self) -> *const ();
}

/// Derive macro generating impls of traits related to smart pointers.
/// Derive macro generating implementations of traits
/// in relation to coercion of types to unsized or dynamic-sized types
/// with dynamic dispatching.
///
/// This macro will enable the target structure to equip with capabilities
/// to weaken a concrete type in its generic parameters to its unsized
/// variants.
/// For instance, it admits coercion of a `[T; SIZE]` to `[T]` where `SIZE`
/// is a constant; and coercion of a concrete type `T` to `dyn Trait` when
/// `T` implements an object-safe trait `Trait`.
/// See the [DST coercion RFC][RFC982] and
/// [the nomicon entry on coercion][nomicon-coerce] on the topics of this coercion.
///
/// The macro would choose a generic parameter labeld by a `#[pointee]` attribute first,
/// and resorts to the first type parameter from the left of
/// the list of generics as the target parameter that
/// the weakening is allowed.
///
/// # Pre-requisites
/// Applying this macro demands the following pre-requisites on the target item.
/// - The target item is a `struct`.
/// - The `struct` has a transparent data layout via `#[repr(transparent)]`.
/// - The `struct` has at least one data field.
/// - The `struct` has at least one generic type parameter.
/// - The `struct` has at most one generic type parameter
/// with macro attribute `#[pointee]` attached.
///
/// [nomicon-coerce]: ../../nomicon/coercions.html
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
#[cfg(not(bootstrap))]
#[stable(feature = "derive_coerce_pointee", since = "CURRENT_RUSTC_VERSION")]
pub macro CoercePointee($item:item) {
/* compiler built-in */
}
2 changes: 0 additions & 2 deletions tests/ui/deriving/coerce-pointee-bounds-issue-127647.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//@ check-pass

#![feature(derive_coerce_pointee)]

#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/deriving/deriving-coerce-pointee-neg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(derive_coerce_pointee, arbitrary_self_types)]
#![feature(arbitrary_self_types)]

extern crate core;
use std::marker::CoercePointee;
Expand Down
3 changes: 2 additions & 1 deletion tests/ui/deriving/deriving-coerce-pointee.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ run-pass
#![feature(derive_coerce_pointee, arbitrary_self_types)]

#![feature(arbitrary_self_types)]

use std::marker::CoercePointee;

Expand Down

0 comments on commit 8baca16

Please sign in to comment.