Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize derive(CoercePointee) #133820

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,11 +1075,45 @@ 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 labelled 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.
/// - The only data field of this `struct` has a type that also implements the same
/// coercion protocol.
/// For instance, this type can be `Box` or `Rc` in the full standard library, or
/// another custom type with the [`CoercePointee`] derived.
///
/// For more information, please refer to [the feature RFC][RFC3621].
///
/// [nomicon-coerce]: ../../nomicon/coercions.html
/// [RFC982]: <https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md>
/// [RFC3621]: <https://github.com/rust-lang/rfcs/pull/3621>
#[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))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question:

Do we need to condition on bootstrap? No standard library item depends on this macro yet.

#[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
9 changes: 0 additions & 9 deletions tests/ui/feature-gates/feature-gate-derive-coerce-pointee.rs

This file was deleted.

23 changes: 0 additions & 23 deletions tests/ui/feature-gates/feature-gate-derive-coerce-pointee.stderr

This file was deleted.

Loading