Skip to content

Commit 81d6652

Browse files
committed
Auto merge of #131284 - dingxiangfei2009:rename-smart-ptr-to-coerce-referent, r=compiler-errors
Rename macro `SmartPointer` to `CoercePointee` As per resolution #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`
2 parents 5f5c243 + 6cb84fe commit 81d6652

24 files changed

+252
-234
lines changed

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! path {
1919
($span:expr, $($part:ident)::*) => { vec![$(Ident::new(sym::$part, $span),)*] }
2020
}
2121

22-
pub(crate) fn expand_deriving_smart_ptr(
22+
pub(crate) fn expand_deriving_coerce_pointee(
2323
cx: &ExtCtxt<'_>,
2424
span: Span,
2525
_mitem: &MetaItem,
@@ -41,7 +41,7 @@ pub(crate) fn expand_deriving_smart_ptr(
4141
cx.dcx()
4242
.struct_span_err(
4343
span,
44-
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
44+
"`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`",
4545
)
4646
.emit();
4747
return;
@@ -54,7 +54,7 @@ pub(crate) fn expand_deriving_smart_ptr(
5454
cx.dcx()
5555
.struct_span_err(
5656
span,
57-
"`SmartPointer` can only be derived on `struct`s with at least one field",
57+
"`CoercePointee` can only be derived on `struct`s with at least one field",
5858
)
5959
.emit();
6060
return;
@@ -64,7 +64,7 @@ pub(crate) fn expand_deriving_smart_ptr(
6464
cx.dcx()
6565
.struct_span_err(
6666
span,
67-
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
67+
"`CoercePointee` can only be derived on `struct`s with `#[repr(transparent)]`",
6868
)
6969
.emit();
7070
return;
@@ -94,10 +94,10 @@ pub(crate) fn expand_deriving_smart_ptr(
9494
.collect();
9595

9696
let pointee_param_idx = if type_params.is_empty() {
97-
// `#[derive(SmartPointer)]` requires at least one generic type on the target `struct`
97+
// `#[derive(CoercePointee)]` requires at least one generic type on the target `struct`
9898
cx.dcx().struct_span_err(
9999
span,
100-
"`SmartPointer` can only be derived on `struct`s that are generic over at least one type",
100+
"`CoercePointee` can only be derived on `struct`s that are generic over at least one type",
101101
).emit();
102102
return;
103103
} else if type_params.len() == 1 {
@@ -113,15 +113,15 @@ pub(crate) fn expand_deriving_smart_ptr(
113113
(None, _) => {
114114
cx.dcx().struct_span_err(
115115
span,
116-
"exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits",
116+
"exactly one generic type parameter must be marked as #[pointee] to derive CoercePointee traits",
117117
).emit();
118118
return;
119119
}
120120
(Some((_, one)), Some((_, another))) => {
121121
cx.dcx()
122122
.struct_span_err(
123123
vec![one, another],
124-
"only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits",
124+
"only one type parameter can be marked as `#[pointee]` when deriving CoercePointee traits",
125125
)
126126
.emit();
127127
return;
@@ -185,7 +185,7 @@ pub(crate) fn expand_deriving_smart_ptr(
185185
.struct_span_err(
186186
pointee_ty_ident.span,
187187
format!(
188-
"`derive(SmartPointer)` requires {} to be marked `?Sized`",
188+
"`derive(CoercePointee)` requires {} to be marked `?Sized`",
189189
pointee_ty_ident.name
190190
),
191191
)
@@ -195,7 +195,7 @@ pub(crate) fn expand_deriving_smart_ptr(
195195
let arg = GenericArg::Type(s_ty.clone());
196196
let unsize = cx.path_all(span, true, path!(span, core::marker::Unsize), vec![arg]);
197197
pointee.bounds.push(cx.trait_bound(unsize, false));
198-
// Drop `#[pointee]` attribute since it should not be recognized outside `derive(SmartPointer)`
198+
// Drop `#[pointee]` attribute since it should not be recognized outside `derive(CoercePointee)`
199199
pointee.attrs.retain(|attr| !attr.has_name(sym::pointee));
200200
}
201201

compiler/rustc_builtin_macros/src/deriving/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ macro path_std($($x:tt)*) {
2222

2323
pub(crate) mod bounds;
2424
pub(crate) mod clone;
25+
pub(crate) mod coerce_pointee;
2526
pub(crate) mod debug;
2627
pub(crate) mod decodable;
2728
pub(crate) mod default;
2829
pub(crate) mod encodable;
2930
pub(crate) mod hash;
30-
pub(crate) mod smart_ptr;
3131

3232
#[path = "cmp/eq.rs"]
3333
pub(crate) mod eq;

compiler/rustc_builtin_macros/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
133133
PartialOrd: partial_ord::expand_deriving_partial_ord,
134134
RustcDecodable: decodable::expand_deriving_rustc_decodable,
135135
RustcEncodable: encodable::expand_deriving_rustc_encodable,
136-
SmartPointer: smart_ptr::expand_deriving_smart_ptr,
136+
CoercePointee: coerce_pointee::expand_deriving_coerce_pointee,
137137
}
138138

139139
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);

compiler/rustc_feature/src/removed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ declare_features! (
8585
/// Allows default type parameters to influence type inference.
8686
(removed, default_type_parameter_fallback, "1.82.0", Some(27336),
8787
Some("never properly implemented; requires significant design work")),
88+
/// Allows deriving traits as per `SmartPointer` specification
89+
(removed, derive_smart_pointer, "1.79.0", Some(123430), Some("replaced by `CoercePointee`")),
8890
/// Allows using `#[doc(keyword = "...")]`.
8991
(removed, doc_keyword, "1.28.0", Some(51315),
9092
Some("merged into `#![feature(rustdoc_internals)]`")),

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ declare_features! (
450450
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
451451
/// Allows deref patterns.
452452
(incomplete, deref_patterns, "1.79.0", Some(87121)),
453-
/// Allows deriving `SmartPointer` traits
454-
(unstable, derive_smart_pointer, "1.79.0", Some(123430)),
455453
/// Controls errors in trait implementations.
456454
(unstable, do_not_recommend, "1.67.0", Some(51992)),
457455
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
262262
| sym::cfg_attr
263263
// need to be fixed
264264
| sym::cfi_encoding // FIXME(cfi_encoding)
265-
| sym::pointee // FIXME(derive_smart_pointer)
265+
| sym::pointee // FIXME(derive_coerce_pointee)
266266
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
267267
| sym::used // handled elsewhere to restrict to static items
268268
| sym::repr // handled elsewhere to restrict to type decls items

compiler/rustc_span/src/symbol.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ symbols! {
174174
Center,
175175
Cleanup,
176176
Clone,
177+
CoercePointee,
177178
CoerceUnsized,
178179
Command,
179180
ConstParamTy,
@@ -307,7 +308,6 @@ symbols! {
307308
Sized,
308309
SliceIndex,
309310
SliceIter,
310-
SmartPointer,
311311
Some,
312312
SpanCtxt,
313313
String,
@@ -732,6 +732,7 @@ symbols! {
732732
deref_pure,
733733
deref_target,
734734
derive,
735+
derive_coerce_pointee,
735736
derive_const,
736737
derive_default_enum,
737738
derive_smart_pointer,

library/core/src/marker.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,10 @@ pub trait FnPtr: Copy + Clone {
10631063
}
10641064

10651065
/// Derive macro generating impls of traits related to smart pointers.
1066-
#[rustc_builtin_macro(SmartPointer, attributes(pointee))]
1066+
#[rustc_builtin_macro(CoercePointee, attributes(pointee))]
10671067
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
1068-
#[unstable(feature = "derive_smart_pointer", issue = "123430")]
1069-
pub macro SmartPointer($item:item) {
1068+
#[unstable(feature = "derive_coerce_pointee", issue = "123430")]
1069+
#[cfg(not(bootstrap))]
1070+
pub macro CoercePointee($item:item) {
10701071
/* compiler built-in */
10711072
}

tests/ui/deriving/auxiliary/another-proc-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
extern crate proc_macro;
88

9-
use proc_macro::{quote, TokenStream};
9+
use proc_macro::{TokenStream, quote};
1010

1111
#[proc_macro_derive(AnotherMacro, attributes(pointee))]
1212
pub fn derive(_input: TokenStream) -> TokenStream {

tests/ui/deriving/built-in-proc-macro-scope.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//@ aux-build: another-proc-macro.rs
33
//@ compile-flags: -Zunpretty=expanded
44

5-
#![feature(derive_smart_pointer)]
5+
#![feature(derive_coerce_pointee)]
66

77
#[macro_use]
88
extern crate another_proc_macro;
99

10-
use another_proc_macro::{pointee, AnotherMacro};
10+
use another_proc_macro::{AnotherMacro, pointee};
1111

12-
#[derive(core::marker::SmartPointer)]
12+
#[derive(core::marker::CoercePointee)]
1313
#[repr(transparent)]
1414
pub struct Ptr<'a, #[pointee] T: ?Sized> {
1515
data: &'a mut T,

tests/ui/deriving/built-in-proc-macro-scope.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@ aux-build: another-proc-macro.rs
55
//@ compile-flags: -Zunpretty=expanded
66

7-
#![feature(derive_smart_pointer)]
7+
#![feature(derive_coerce_pointee)]
88
#[prelude_import]
99
use ::std::prelude::rust_2015::*;
1010
#[macro_use]
@@ -13,7 +13,7 @@ extern crate std;
1313
#[macro_use]
1414
extern crate another_proc_macro;
1515

16-
use another_proc_macro::{pointee, AnotherMacro};
16+
use another_proc_macro::{AnotherMacro, pointee};
1717

1818
#[repr(transparent)]
1919
pub struct Ptr<'a, #[pointee] T: ?Sized> {

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//@ check-pass
22

3-
#![feature(derive_smart_pointer)]
3+
#![feature(derive_coerce_pointee)]
44

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

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

2626
pub trait MyTrait<T: ?Sized> {}
2727

28-
#[derive(core::marker::SmartPointer)]
28+
#[derive(core::marker::CoercePointee)]
2929
#[repr(transparent)]
3030
pub struct Ptr3<'a, #[pointee] T: ?Sized, X>
3131
where
@@ -35,14 +35,14 @@ where
3535
x: core::marker::PhantomData<X>,
3636
}
3737

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

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

59-
#[derive(core::marker::SmartPointer)]
59+
#[derive(core::marker::CoercePointee)]
6060
#[repr(transparent)]
6161
pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T> = (), const PARAM: usize = 0> {
6262
data: &'a mut T,
@@ -65,7 +65,7 @@ pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T> = (), const PARAM: usize
6565

6666
// a reduced example from https://lore.kernel.org/all/20240402-linked-list-v1-1-b1c59ba7ae3b@google.com/
6767
#[repr(transparent)]
68-
#[derive(core::marker::SmartPointer)]
68+
#[derive(core::marker::CoercePointee)]
6969
pub struct ListArc<#[pointee] T, const ID: u64 = 0>
7070
where
7171
T: ListArcSafe<ID> + ?Sized,

tests/ui/deriving/deriving-smart-pointer-expanded.rs tests/ui/deriving/deriving-coerce-pointee-expanded.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//@ check-pass
22
//@ compile-flags: -Zunpretty=expanded
3-
#![feature(derive_smart_pointer)]
4-
use std::marker::SmartPointer;
3+
#![feature(derive_coerce_pointee)]
4+
use std::marker::CoercePointee;
55

66
pub trait MyTrait<T: ?Sized> {}
77

8-
#[derive(SmartPointer)]
8+
#[derive(CoercePointee)]
99
#[repr(transparent)]
1010
struct MyPointer<'a, #[pointee] T: ?Sized> {
1111
ptr: &'a T,
1212
}
1313

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

24-
#[derive(SmartPointer)]
24+
#[derive(CoercePointee)]
2525
#[repr(transparent)]
2626
struct MyPointerWithoutPointee<'a, T: ?Sized> {
2727
ptr: &'a T,

tests/ui/deriving/deriving-smart-pointer-expanded.stdout tests/ui/deriving/deriving-coerce-pointee-expanded.stdout

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#![no_std]
33
//@ check-pass
44
//@ compile-flags: -Zunpretty=expanded
5-
#![feature(derive_smart_pointer)]
5+
#![feature(derive_coerce_pointee)]
66
#[prelude_import]
77
use ::std::prelude::rust_2015::*;
88
#[macro_use]
99
extern crate std;
10-
use std::marker::SmartPointer;
10+
use std::marker::CoercePointee;
1111

1212
pub trait MyTrait<T: ?Sized> {}
1313

0 commit comments

Comments
 (0)