Skip to content

Commit

Permalink
Auto merge of rust-lang#131284 - dingxiangfei2009:rename-smart-ptr-to…
Browse files Browse the repository at this point in the history
…-coerce-referent, r=compiler-errors

Rename macro `SmartPointer` to `CoercePointee`

As per resolution rust-lang#129104 we will rename the macro to better reflect the technical specification of the feature and clarify the communication.

- `SmartPointer` is renamed to `CoerceReferent`
- `#[pointee]` attribute is renamed to `#[referent]`
- `#![feature(derive_smart_pointer)]` gate is renamed to `#![feature(derive_coerce_referent)]`.
- Any mention of `SmartPointer` in the file names are renamed accordingly.

r? `@compiler-errors`

cc `@nikomatsakis` `@Darksonn`
  • Loading branch information
bors committed Oct 27, 2024
2 parents 5f5c243 + 6cb84fe commit 81d6652
Show file tree
Hide file tree
Showing 24 changed files with 252 additions and 234 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! path {
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
}

pub(crate) fn expand_deriving_smart_ptr(
pub(crate) fn expand_deriving_coerce_pointee(
cx: &ExtCtxt<'_>,
span: Span,
_mitem: &MetaItem,
Expand All @@ -41,7 +41,7 @@ pub(crate) fn expand_deriving_smart_ptr(
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
"`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`",
)
.emit();
return;
Expand All @@ -54,7 +54,7 @@ pub(crate) fn expand_deriving_smart_ptr(
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with at least one field",
"`CoercePointee` can only be derived on `struct`s with at least one field",
)
.emit();
return;
Expand All @@ -64,7 +64,7 @@ pub(crate) fn expand_deriving_smart_ptr(
cx.dcx()
.struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
"`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`",
)
.emit();
return;
Expand Down Expand Up @@ -94,10 +94,10 @@ pub(crate) fn expand_deriving_smart_ptr(
.collect();

let pointee_param_idx = if type_params.is_empty() {
// `#[derive(SmartPointer)]` requires at least one generic type on the target `struct`
// `#[derive(CoercePointee)]` requires at least one generic type on the target `struct`
cx.dcx().struct_span_err(
span,
"`SmartPointer` can only be derived on `struct`s that are generic over at least one type",
"`CoercePointee` can only be derived on `struct`s that are generic over at least one type",
).emit();
return;
} else if type_params.len() == 1 {
Expand All @@ -113,15 +113,15 @@ pub(crate) fn expand_deriving_smart_ptr(
(None, _) => {
cx.dcx().struct_span_err(
span,
"exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits",
"exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits",
).emit();
return;
}
(Some((_, one)), Some((_, another))) => {
cx.dcx()
.struct_span_err(
vec![one, another],
"only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits",
"only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits",
)
.emit();
return;
Expand Down Expand Up @@ -185,7 +185,7 @@ pub(crate) fn expand_deriving_smart_ptr(
.struct_span_err(
pointee_ty_ident.span,
format!(
"`derive(SmartPointer)` requires {} to be marked `?Sized`",
"`derive(CoercePointee)` requires {} to be marked `?Sized`",
pointee_ty_ident.name
),
)
Expand All @@ -195,7 +195,7 @@ pub(crate) fn expand_deriving_smart_ptr(
let arg = GenericArg::Type(s_ty.clone());
let unsize = cx.path_all(span, true, path!(span, core::marker::Unsize), vec![arg]);
pointee.bounds.push(cx.trait_bound(unsize, false));
// Drop `#[pointee]` attribute since it should not be recognized outside `derive(SmartPointer)`
// Drop `#[pointee]` attribute since it should not be recognized outside `derive(CoercePointee)`
pointee.attrs.retain(|attr| !attr.has_name(sym::pointee));
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ macro path_std($($x:tt)*) {

pub(crate) mod bounds;
pub(crate) mod clone;
pub(crate) mod coerce_pointee;
pub(crate) mod debug;
pub(crate) mod decodable;
pub(crate) mod default;
pub(crate) mod encodable;
pub(crate) mod hash;
pub(crate) mod smart_ptr;

#[path = "cmp/eq.rs"]
pub(crate) mod eq;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
PartialOrd: partial_ord::expand_deriving_partial_ord,
RustcDecodable: decodable::expand_deriving_rustc_decodable,
RustcEncodable: encodable::expand_deriving_rustc_encodable,
SmartPointer: smart_ptr::expand_deriving_smart_ptr,
CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
}

let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ declare_features! (
/// Allows default type parameters to influence type inference.
(removed, default_type_parameter_fallback, "1.82.0", Some(27336),
Some("never properly implemented; requires significant design work")),
/// Allows deriving traits as per `SmartPointer` specification
(removed, derive_smart_pointer, "1.79.0", Some(123430), Some("replaced by `CoercePointee`")),
/// Allows using `#[doc(keyword = "...")]`.
(removed, doc_keyword, "1.28.0", Some(51315),
Some("merged into `#![feature(rustdoc_internals)]`")),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,6 @@ declare_features! (
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
/// Allows deref patterns.
(incomplete, deref_patterns, "1.79.0", Some(87121)),
/// Allows deriving `SmartPointer` traits
(unstable, derive_smart_pointer, "1.79.0", Some(123430)),
/// Controls errors in trait implementations.
(unstable, do_not_recommend, "1.67.0", Some(51992)),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| sym::cfg_attr
// need to be fixed
| sym::cfi_encoding // FIXME(cfi_encoding)
| sym::pointee // FIXME(derive_smart_pointer)
| sym::pointee // FIXME(derive_coerce_pointee)
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
| sym::used // handled elsewhere to restrict to static items
| sym::repr // handled elsewhere to restrict to type decls items
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ symbols! {
Center,
Cleanup,
Clone,
CoercePointee,
CoerceUnsized,
Command,
ConstParamTy,
Expand Down Expand Up @@ -307,7 +308,6 @@ symbols! {
Sized,
SliceIndex,
SliceIter,
SmartPointer,
Some,
SpanCtxt,
String,
Expand Down Expand Up @@ -732,6 +732,7 @@ symbols! {
deref_pure,
deref_target,
derive,
derive_coerce_pointee,
derive_const,
derive_default_enum,
derive_smart_pointer,
Expand Down
7 changes: 4 additions & 3 deletions library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,9 +1063,10 @@ pub trait FnPtr: Copy + Clone {
}

/// Derive macro generating impls of traits related to smart pointers.
#[rustc_builtin_macro(SmartPointer, attributes(pointee))]
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
#[unstable(feature = "derive_smart_pointer", issue = "123430")]
pub macro SmartPointer($item:item) {
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
#[cfg(not(bootstrap))]
pub macro CoercePointee($item:item) {
/* compiler built-in */
}
2 changes: 1 addition & 1 deletion tests/ui/deriving/auxiliary/another-proc-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

extern crate proc_macro;

use proc_macro::{quote, TokenStream};
use proc_macro::{TokenStream, quote};

#[proc_macro_derive(AnotherMacro, attributes(pointee))]
pub fn derive(_input: TokenStream) -> TokenStream {
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/deriving/built-in-proc-macro-scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//@ aux-build: another-proc-macro.rs
//@ compile-flags: -Zunpretty=expanded

#![feature(derive_smart_pointer)]
#![feature(derive_coerce_pointee)]

#[macro_use]
extern crate another_proc_macro;

use another_proc_macro::{pointee, AnotherMacro};
use another_proc_macro::{AnotherMacro, pointee};

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr<'a, #[pointee] T: ?Sized> {
data: &'a mut T,
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/deriving/built-in-proc-macro-scope.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ aux-build: another-proc-macro.rs
//@ compile-flags: -Zunpretty=expanded

#![feature(derive_smart_pointer)]
#![feature(derive_coerce_pointee)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
Expand All @@ -13,7 +13,7 @@ extern crate std;
#[macro_use]
extern crate another_proc_macro;

use another_proc_macro::{pointee, AnotherMacro};
use another_proc_macro::{AnotherMacro, pointee};

#[repr(transparent)]
pub struct Ptr<'a, #[pointee] T: ?Sized> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//@ check-pass

#![feature(derive_smart_pointer)]
#![feature(derive_coerce_pointee)]

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr<'a, #[pointee] T: OnDrop + ?Sized, X> {
data: &'a mut T,
Expand All @@ -13,7 +13,7 @@ pub trait OnDrop {
fn on_drop(&mut self);
}

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr2<'a, #[pointee] T: ?Sized, X>
where
Expand All @@ -25,7 +25,7 @@ where

pub trait MyTrait<T: ?Sized> {}

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr3<'a, #[pointee] T: ?Sized, X>
where
Expand All @@ -35,14 +35,14 @@ where
x: core::marker::PhantomData<X>,
}

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr4<'a, #[pointee] T: MyTrait<T> + ?Sized, X> {
data: &'a mut T,
x: core::marker::PhantomData<X>,
}

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr5<'a, #[pointee] T: ?Sized, X>
where
Expand All @@ -56,7 +56,7 @@ where
pub struct Ptr5Companion<T: ?Sized>(core::marker::PhantomData<T>);
pub struct Ptr5Companion2;

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T> = (), const PARAM: usize = 0> {
data: &'a mut T,
Expand All @@ -65,7 +65,7 @@ pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T> = (), 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::SmartPointer)]
#[derive(core::marker::CoercePointee)]
pub struct ListArc<#[pointee] T, const ID: u64 = 0>
where
T: ListArcSafe<ID> + ?Sized,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
//@ check-pass
//@ compile-flags: -Zunpretty=expanded
#![feature(derive_smart_pointer)]
use std::marker::SmartPointer;
#![feature(derive_coerce_pointee)]
use std::marker::CoercePointee;

pub trait MyTrait<T: ?Sized> {}

#[derive(SmartPointer)]
#[derive(CoercePointee)]
#[repr(transparent)]
struct MyPointer<'a, #[pointee] T: ?Sized> {
ptr: &'a T,
}

#[derive(core::marker::SmartPointer)]
#[derive(core::marker::CoercePointee)]
#[repr(transparent)]
pub struct MyPointer2<'a, Y, Z: MyTrait<T>, #[pointee] T: ?Sized + MyTrait<T>, X: MyTrait<T> = ()>
where
Expand All @@ -21,7 +21,7 @@ where
x: core::marker::PhantomData<X>,
}

#[derive(SmartPointer)]
#[derive(CoercePointee)]
#[repr(transparent)]
struct MyPointerWithoutPointee<'a, T: ?Sized> {
ptr: &'a T,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#![no_std]
//@ check-pass
//@ compile-flags: -Zunpretty=expanded
#![feature(derive_smart_pointer)]
#![feature(derive_coerce_pointee)]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
use std::marker::SmartPointer;
use std::marker::CoercePointee;

pub trait MyTrait<T: ?Sized> {}

Expand Down
Loading

0 comments on commit 81d6652

Please sign in to comment.