Skip to content

Commit ffef110

Browse files
s/SmartPointer/CoerceReferent/g
1 parent 5a4ee43 commit ffef110

22 files changed

+216
-215
lines changed

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

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

20-
pub(crate) fn expand_deriving_smart_ptr(
20+
pub(crate) fn expand_deriving_coerce_referent(
2121
cx: &ExtCtxt<'_>,
2222
span: Span,
2323
_mitem: &MetaItem,
@@ -37,7 +37,7 @@ pub(crate) fn expand_deriving_smart_ptr(
3737
cx.dcx()
3838
.struct_span_err(
3939
span,
40-
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
40+
"`CoerceReferent` can only be derived on `struct`s with `#[repr(transparent)]`",
4141
)
4242
.emit();
4343
return;
@@ -50,7 +50,7 @@ pub(crate) fn expand_deriving_smart_ptr(
5050
cx.dcx()
5151
.struct_span_err(
5252
span,
53-
"`SmartPointer` can only be derived on `struct`s with at least one field",
53+
"`CoerceReferent` can only be derived on `struct`s with at least one field",
5454
)
5555
.emit();
5656
return;
@@ -60,7 +60,7 @@ pub(crate) fn expand_deriving_smart_ptr(
6060
cx.dcx()
6161
.struct_span_err(
6262
span,
63-
"`SmartPointer` can only be derived on `struct`s with `#[repr(transparent)]`",
63+
"`CoerceReferent` can only be derived on `struct`s with `#[repr(transparent)]`",
6464
)
6565
.emit();
6666
return;
@@ -82,42 +82,42 @@ pub(crate) fn expand_deriving_smart_ptr(
8282
.enumerate()
8383
.filter_map(|(idx, p)| {
8484
if let GenericParamKind::Type { .. } = p.kind {
85-
Some((idx, p.span(), p.attrs().iter().any(|attr| attr.has_name(sym::pointee))))
85+
Some((idx, p.span(), p.attrs().iter().any(|attr| attr.has_name(sym::referent))))
8686
} else {
8787
None
8888
}
8989
})
9090
.collect();
9191

92-
let pointee_param_idx = if type_params.is_empty() {
93-
// `#[derive(SmartPointer)]` requires at least one generic type on the target `struct`
92+
let referent_param_idx = if type_params.is_empty() {
93+
// `#[derive(CoerceReferent)]` requires at least one generic type on the target `struct`
9494
cx.dcx().struct_span_err(
9595
span,
96-
"`SmartPointer` can only be derived on `struct`s that are generic over at least one type",
96+
"`CoerceReferent` can only be derived on `struct`s that are generic over at least one type",
9797
).emit();
9898
return;
9999
} else if type_params.len() == 1 {
100-
// Regardless of the only type param being designed as `#[pointee]` or not, we can just use it as such
100+
// Regardless of the only type param being designed as `#[referent]` or not, we can just use it as such
101101
type_params[0].0
102102
} else {
103-
let mut pointees = type_params
103+
let mut referents = type_params
104104
.iter()
105-
.filter_map(|&(idx, span, is_pointee)| is_pointee.then_some((idx, span)))
105+
.filter_map(|&(idx, span, is_referent)| is_referent.then_some((idx, span)))
106106
.fuse();
107-
match (pointees.next(), pointees.next()) {
107+
match (referents.next(), referents.next()) {
108108
(Some((idx, _span)), None) => idx,
109109
(None, _) => {
110110
cx.dcx().struct_span_err(
111111
span,
112-
"exactly one generic type parameter must be marked as #[pointee] to derive SmartPointer traits",
112+
"exactly one generic type parameter must be marked as #[referent] to derive CoerceReferent traits",
113113
).emit();
114114
return;
115115
}
116116
(Some((_, one)), Some((_, another))) => {
117117
cx.dcx()
118118
.struct_span_err(
119119
vec![one, another],
120-
"only one type parameter can be marked as `#[pointee]` when deriving SmartPointer traits",
120+
"only one type parameter can be marked as `#[referent]` when deriving CoerceReferent traits",
121121
)
122122
.emit();
123123
return;
@@ -155,53 +155,53 @@ pub(crate) fn expand_deriving_smart_ptr(
155155
push(Annotatable::Item(item));
156156
};
157157

158-
// Create unsized `self`, that is, one where the `#[pointee]` type arg is replaced with `__S`. For
158+
// Create unsized `self`, that is, one where the `#[referent]` type arg is replaced with `__S`. For
159159
// example, instead of `MyType<'a, T>`, it will be `MyType<'a, __S>`.
160160
let s_ty = cx.ty_ident(span, Ident::new(sym::__S, span));
161161
let mut alt_self_params = self_params;
162-
alt_self_params[pointee_param_idx] = GenericArg::Type(s_ty.clone());
162+
alt_self_params[referent_param_idx] = GenericArg::Type(s_ty.clone());
163163
let alt_self_type = cx.ty_path(cx.path_all(span, false, vec![name_ident], alt_self_params));
164164

165-
// # Add `Unsize<__S>` bound to `#[pointee]` at the generic parameter location
165+
// # Add `Unsize<__S>` bound to `#[referent]` at the generic parameter location
166166
//
167-
// Find the `#[pointee]` parameter and add an `Unsize<__S>` bound to it.
167+
// Find the `#[referent]` parameter and add an `Unsize<__S>` bound to it.
168168
let mut impl_generics = generics.clone();
169-
let pointee_ty_ident = generics.params[pointee_param_idx].ident;
169+
let referent_ty_ident = generics.params[referent_param_idx].ident;
170170
let mut self_bounds;
171171
{
172-
let pointee = &mut impl_generics.params[pointee_param_idx];
173-
self_bounds = pointee.bounds.clone();
172+
let referent = &mut impl_generics.params[referent_param_idx];
173+
self_bounds = referent.bounds.clone();
174174
if !contains_maybe_sized_bound(&self_bounds)
175-
&& !contains_maybe_sized_bound_on_pointee(
175+
&& !contains_maybe_sized_bound_on_referent(
176176
&generics.where_clause.predicates,
177-
pointee_ty_ident.name,
177+
referent_ty_ident.name,
178178
)
179179
{
180180
cx.dcx()
181181
.struct_span_err(
182-
pointee_ty_ident.span,
182+
referent_ty_ident.span,
183183
format!(
184-
"`derive(SmartPointer)` requires {} to be marked `?Sized`",
185-
pointee_ty_ident.name
184+
"`derive(CoerceReferent)` requires {} to be marked `?Sized`",
185+
referent_ty_ident.name
186186
),
187187
)
188188
.emit();
189189
return;
190190
}
191191
let arg = GenericArg::Type(s_ty.clone());
192192
let unsize = cx.path_all(span, true, path!(span, core::marker::Unsize), vec![arg]);
193-
pointee.bounds.push(cx.trait_bound(unsize, false));
194-
// Drop `#[pointee]` attribute since it should not be recognized outside `derive(SmartPointer)`
195-
pointee.attrs.retain(|attr| !attr.has_name(sym::pointee));
193+
referent.bounds.push(cx.trait_bound(unsize, false));
194+
// Drop `#[referent]` attribute since it should not be recognized outside `derive(CoerceReferent)`
195+
referent.attrs.retain(|attr| !attr.has_name(sym::referent));
196196
}
197197

198198
// # Rewrite generic parameter bounds
199-
// For each bound `U: ..` in `struct<U: ..>`, make a new bound with `__S` in place of `#[pointee]`
199+
// For each bound `U: ..` in `struct<U: ..>`, make a new bound with `__S` in place of `#[referent]`
200200
// Example:
201201
// ```
202202
// struct<
203203
// U: Trait<T>,
204-
// #[pointee] T: Trait<T> + ?Sized,
204+
// #[referent] T: Trait<T> + ?Sized,
205205
// V: Trait<T>> ...
206206
// ```
207207
// ... generates this `impl` generic parameters
@@ -224,22 +224,22 @@ pub(crate) fn expand_deriving_smart_ptr(
224224
ast::GenericParamKind::Type { default } => *default = None,
225225
ast::GenericParamKind::Lifetime => {}
226226
}
227-
// We CANNOT rewrite `#[pointee]` type parameter bounds.
227+
// We CANNOT rewrite `#[referent]` type parameter bounds.
228228
// This has been set in stone. (**)
229229
// So we skip over it.
230230
// Otherwise, we push extra bounds involving `__S`.
231-
if idx != pointee_param_idx {
231+
if idx != referent_param_idx {
232232
for bound in &orig_params.bounds {
233233
let mut bound = bound.clone();
234234
let mut substitution = TypeSubstitution {
235-
from_name: pointee_ty_ident.name,
235+
from_name: referent_ty_ident.name,
236236
to_ty: &s_ty,
237237
rewritten: false,
238238
};
239239
substitution.visit_param_bound(&mut bound, BoundKind::Bound);
240240
if substitution.rewritten {
241-
// We found use of `#[pointee]` somewhere,
242-
// so we make a new bound using `__S` in place of `#[pointee]`
241+
// We found use of `#[referent]` somewhere,
242+
// so we make a new bound using `__S` in place of `#[referent]`
243243
params.bounds.push(bound);
244244
}
245245
}
@@ -249,10 +249,10 @@ pub(crate) fn expand_deriving_smart_ptr(
249249
// # Insert `__S` type parameter
250250
//
251251
// We now insert `__S` with the missing bounds marked with (*) above.
252-
// We should also write the bounds from `#[pointee]` to `__S` as required by `Unsize<__S>`.
252+
// We should also write the bounds from `#[referent]` to `__S` as required by `Unsize<__S>`.
253253
{
254254
let mut substitution =
255-
TypeSubstitution { from_name: pointee_ty_ident.name, to_ty: &s_ty, rewritten: false };
255+
TypeSubstitution { from_name: referent_ty_ident.name, to_ty: &s_ty, rewritten: false };
256256
for bound in &mut self_bounds {
257257
substitution.visit_param_bound(bound, BoundKind::Bound);
258258
}
@@ -263,7 +263,7 @@ pub(crate) fn expand_deriving_smart_ptr(
263263
// Move on to `where` clauses.
264264
// Example:
265265
// ```
266-
// struct MyPointer<#[pointee] T, ..>
266+
// struct MyPointer<#[referent] T, ..>
267267
// where
268268
// U: Trait<V> + Trait<T>,
269269
// Companion<T>: Trait<T>,
@@ -282,12 +282,12 @@ pub(crate) fn expand_deriving_smart_ptr(
282282
// __S: Trait<__S> + ?Sized,
283283
// ```
284284
//
285-
// We should also write a few new `where` bounds from `#[pointee] T` to `__S`
286-
// as well as any bound that indirectly involves the `#[pointee] T` type.
285+
// We should also write a few new `where` bounds from `#[referent] T` to `__S`
286+
// as well as any bound that indirectly involves the `#[referent] T` type.
287287
for bound in &generics.where_clause.predicates {
288288
if let ast::WherePredicate::BoundPredicate(bound) = bound {
289289
let mut substitution = TypeSubstitution {
290-
from_name: pointee_ty_ident.name,
290+
from_name: referent_ty_ident.name,
291291
to_ty: &s_ty,
292292
rewritten: false,
293293
};
@@ -305,18 +305,18 @@ pub(crate) fn expand_deriving_smart_ptr(
305305
}
306306

307307
let extra_param = cx.typaram(span, Ident::new(sym::__S, span), self_bounds, None);
308-
impl_generics.params.insert(pointee_param_idx + 1, extra_param);
308+
impl_generics.params.insert(referent_param_idx + 1, extra_param);
309309

310310
// Add the impl blocks for `DispatchFromDyn` and `CoerceUnsized`.
311311
let gen_args = vec![GenericArg::Type(alt_self_type.clone())];
312312
add_impl_block(impl_generics.clone(), sym::DispatchFromDyn, gen_args.clone());
313313
add_impl_block(impl_generics.clone(), sym::CoerceUnsized, gen_args);
314314
}
315315

316-
fn contains_maybe_sized_bound_on_pointee(predicates: &[WherePredicate], pointee: Symbol) -> bool {
316+
fn contains_maybe_sized_bound_on_referent(predicates: &[WherePredicate], referent: Symbol) -> bool {
317317
for bound in predicates {
318318
if let ast::WherePredicate::BoundPredicate(bound) = bound
319-
&& bound.bounded_ty.kind.is_simple_path().is_some_and(|name| name == pointee)
319+
&& bound.bounded_ty.kind.is_simple_path().is_some_and(|name| name == referent)
320320
{
321321
for bound in &bound.bounds {
322322
if is_maybe_sized_bound(bound) {

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_referent;
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
@@ -130,7 +130,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
130130
PartialOrd: partial_ord::expand_deriving_partial_ord,
131131
RustcDecodable: decodable::expand_deriving_rustc_decodable,
132132
RustcEncodable: encodable::expand_deriving_rustc_encodable,
133-
SmartPointer: smart_ptr::expand_deriving_smart_ptr,
133+
CoerceReferent: coerce_referent::expand_deriving_coerce_referent,
134134
}
135135

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

compiler/rustc_feature/src/unstable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ declare_features! (
432432
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
433433
/// Allows deref patterns.
434434
(incomplete, deref_patterns, "1.79.0", Some(87121)),
435-
/// Allows deriving `SmartPointer` traits
436-
(unstable, derive_smart_pointer, "1.79.0", Some(123430)),
435+
/// Allows deriving `CoerceReferent` traits
436+
(unstable, dervie_coerce_referent, "1.79.0", Some(123430)),
437437
/// Controls errors in trait implementations.
438438
(unstable, do_not_recommend, "1.67.0", Some(51992)),
439439
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
259259
| sym::cfg_attr
260260
// need to be fixed
261261
| sym::cfi_encoding // FIXME(cfi_encoding)
262-
| sym::pointee // FIXME(derive_smart_pointer)
262+
| sym::referent // FIXME(dervie_coerce_referent)
263263
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
264264
| sym::used // handled elsewhere to restrict to static items
265265
| sym::repr // handled elsewhere to restrict to type decls items

compiler/rustc_span/src/symbol.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ symbols! {
174174
Center,
175175
Cleanup,
176176
Clone,
177+
CoerceReferent,
177178
CoerceUnsized,
178179
Command,
179180
ConstParamTy,
@@ -315,7 +316,6 @@ symbols! {
315316
Sized,
316317
SliceIndex,
317318
SliceIter,
318-
SmartPointer,
319319
Some,
320320
SpanCtxt,
321321
String,
@@ -739,7 +739,7 @@ symbols! {
739739
derive,
740740
derive_const,
741741
derive_default_enum,
742-
derive_smart_pointer,
742+
dervie_coerce_referent,
743743
destruct,
744744
destructuring_assignment,
745745
diagnostic,
@@ -1460,7 +1460,6 @@ symbols! {
14601460
plugin,
14611461
plugin_registrar,
14621462
plugins,
1463-
pointee,
14641463
pointee_trait,
14651464
pointer,
14661465
pointer_like,
@@ -1571,6 +1570,7 @@ symbols! {
15711570
ref_pat_everywhere,
15721571
ref_unwind_safe_trait,
15731572
reference,
1573+
referent,
15741574
reflect,
15751575
reg,
15761576
reg16,

library/core/src/marker.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,11 @@ pub trait FnPtr: Copy + Clone {
10621062
}
10631063

10641064
/// Derive macro generating impls of traits related to smart pointers.
1065-
#[rustc_builtin_macro(SmartPointer, attributes(pointee))]
1065+
#[rustc_builtin_macro(CoerceReferent, attributes(referent))]
10661066
#[allow_internal_unstable(dispatch_from_dyn, coerce_unsized, unsize)]
1067-
#[unstable(feature = "derive_smart_pointer", issue = "123430")]
1068-
pub macro SmartPointer($item:item) {
1067+
#[unstable(feature = "dervie_coerce_referent", issue = "123430")]
1068+
#[cfg(not(bootstrap))]
1069+
pub macro CoerceReferent($item:item) {
10691070
/* compiler built-in */
10701071
}
10711072

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
extern crate proc_macro;
88

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

11-
#[proc_macro_derive(AnotherMacro, attributes(pointee))]
11+
#[proc_macro_derive(AnotherMacro, attributes(referent))]
1212
pub fn derive(_input: TokenStream) -> TokenStream {
1313
quote! {
1414
const _: () = {
@@ -19,13 +19,13 @@ pub fn derive(_input: TokenStream) -> TokenStream {
1919
}
2020

2121
#[proc_macro_attribute]
22-
pub fn pointee(
22+
pub fn referent(
2323
_attr: proc_macro::TokenStream,
2424
_item: proc_macro::TokenStream,
2525
) -> proc_macro::TokenStream {
2626
quote! {
2727
const _: () = {
28-
const POINTEE_MACRO_ATTR_DERIVED: () = ();
28+
const REFERENT_MACRO_ATTR_DERIVED: () = ();
2929
};
3030
}
3131
.into()

0 commit comments

Comments
 (0)