@@ -17,7 +17,7 @@ macro_rules! path {
17
17
( $span: expr, $( $part: ident) ::* ) => { vec![ $( Ident :: new( sym:: $part, $span) , ) * ] }
18
18
}
19
19
20
- pub ( crate ) fn expand_deriving_smart_ptr (
20
+ pub ( crate ) fn expand_deriving_coerce_referent (
21
21
cx : & ExtCtxt < ' _ > ,
22
22
span : Span ,
23
23
_mitem : & MetaItem ,
@@ -37,7 +37,7 @@ pub(crate) fn expand_deriving_smart_ptr(
37
37
cx. dcx ( )
38
38
. struct_span_err (
39
39
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)]`" ,
41
41
)
42
42
. emit ( ) ;
43
43
return ;
@@ -50,7 +50,7 @@ pub(crate) fn expand_deriving_smart_ptr(
50
50
cx. dcx ( )
51
51
. struct_span_err (
52
52
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" ,
54
54
)
55
55
. emit ( ) ;
56
56
return ;
@@ -60,7 +60,7 @@ pub(crate) fn expand_deriving_smart_ptr(
60
60
cx. dcx ( )
61
61
. struct_span_err (
62
62
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)]`" ,
64
64
)
65
65
. emit ( ) ;
66
66
return ;
@@ -82,42 +82,42 @@ pub(crate) fn expand_deriving_smart_ptr(
82
82
. enumerate ( )
83
83
. filter_map ( |( idx, p) | {
84
84
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 ) ) ) )
86
86
} else {
87
87
None
88
88
}
89
89
} )
90
90
. collect ( ) ;
91
91
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`
94
94
cx. dcx ( ) . struct_span_err (
95
95
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" ,
97
97
) . emit ( ) ;
98
98
return ;
99
99
} 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
101
101
type_params[ 0 ] . 0
102
102
} else {
103
- let mut pointees = type_params
103
+ let mut referents = type_params
104
104
. 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) ) )
106
106
. fuse ( ) ;
107
- match ( pointees . next ( ) , pointees . next ( ) ) {
107
+ match ( referents . next ( ) , referents . next ( ) ) {
108
108
( Some ( ( idx, _span) ) , None ) => idx,
109
109
( None , _) => {
110
110
cx. dcx ( ) . struct_span_err (
111
111
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" ,
113
113
) . emit ( ) ;
114
114
return ;
115
115
}
116
116
( Some ( ( _, one) ) , Some ( ( _, another) ) ) => {
117
117
cx. dcx ( )
118
118
. struct_span_err (
119
119
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" ,
121
121
)
122
122
. emit ( ) ;
123
123
return ;
@@ -155,53 +155,53 @@ pub(crate) fn expand_deriving_smart_ptr(
155
155
push ( Annotatable :: Item ( item) ) ;
156
156
} ;
157
157
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
159
159
// example, instead of `MyType<'a, T>`, it will be `MyType<'a, __S>`.
160
160
let s_ty = cx. ty_ident ( span, Ident :: new ( sym:: __S, span) ) ;
161
161
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 ( ) ) ;
163
163
let alt_self_type = cx. ty_path ( cx. path_all ( span, false , vec ! [ name_ident] , alt_self_params) ) ;
164
164
165
- // # Add `Unsize<__S>` bound to `#[pointee ]` at the generic parameter location
165
+ // # Add `Unsize<__S>` bound to `#[referent ]` at the generic parameter location
166
166
//
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.
168
168
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 ;
170
170
let mut self_bounds;
171
171
{
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 ( ) ;
174
174
if !contains_maybe_sized_bound ( & self_bounds)
175
- && !contains_maybe_sized_bound_on_pointee (
175
+ && !contains_maybe_sized_bound_on_referent (
176
176
& generics. where_clause . predicates ,
177
- pointee_ty_ident . name ,
177
+ referent_ty_ident . name ,
178
178
)
179
179
{
180
180
cx. dcx ( )
181
181
. struct_span_err (
182
- pointee_ty_ident . span ,
182
+ referent_ty_ident . span ,
183
183
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
186
186
) ,
187
187
)
188
188
. emit ( ) ;
189
189
return ;
190
190
}
191
191
let arg = GenericArg :: Type ( s_ty. clone ( ) ) ;
192
192
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 ) ) ;
196
196
}
197
197
198
198
// # 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 ]`
200
200
// Example:
201
201
// ```
202
202
// struct<
203
203
// U: Trait<T>,
204
- // #[pointee ] T: Trait<T> + ?Sized,
204
+ // #[referent ] T: Trait<T> + ?Sized,
205
205
// V: Trait<T>> ...
206
206
// ```
207
207
// ... generates this `impl` generic parameters
@@ -224,22 +224,22 @@ pub(crate) fn expand_deriving_smart_ptr(
224
224
ast:: GenericParamKind :: Type { default } => * default = None ,
225
225
ast:: GenericParamKind :: Lifetime => { }
226
226
}
227
- // We CANNOT rewrite `#[pointee ]` type parameter bounds.
227
+ // We CANNOT rewrite `#[referent ]` type parameter bounds.
228
228
// This has been set in stone. (**)
229
229
// So we skip over it.
230
230
// Otherwise, we push extra bounds involving `__S`.
231
- if idx != pointee_param_idx {
231
+ if idx != referent_param_idx {
232
232
for bound in & orig_params. bounds {
233
233
let mut bound = bound. clone ( ) ;
234
234
let mut substitution = TypeSubstitution {
235
- from_name : pointee_ty_ident . name ,
235
+ from_name : referent_ty_ident . name ,
236
236
to_ty : & s_ty,
237
237
rewritten : false ,
238
238
} ;
239
239
substitution. visit_param_bound ( & mut bound, BoundKind :: Bound ) ;
240
240
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 ]`
243
243
params. bounds . push ( bound) ;
244
244
}
245
245
}
@@ -249,10 +249,10 @@ pub(crate) fn expand_deriving_smart_ptr(
249
249
// # Insert `__S` type parameter
250
250
//
251
251
// 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>`.
253
253
{
254
254
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 } ;
256
256
for bound in & mut self_bounds {
257
257
substitution. visit_param_bound ( bound, BoundKind :: Bound ) ;
258
258
}
@@ -263,7 +263,7 @@ pub(crate) fn expand_deriving_smart_ptr(
263
263
// Move on to `where` clauses.
264
264
// Example:
265
265
// ```
266
- // struct MyPointer<#[pointee ] T, ..>
266
+ // struct MyPointer<#[referent ] T, ..>
267
267
// where
268
268
// U: Trait<V> + Trait<T>,
269
269
// Companion<T>: Trait<T>,
@@ -282,12 +282,12 @@ pub(crate) fn expand_deriving_smart_ptr(
282
282
// __S: Trait<__S> + ?Sized,
283
283
// ```
284
284
//
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.
287
287
for bound in & generics. where_clause . predicates {
288
288
if let ast:: WherePredicate :: BoundPredicate ( bound) = bound {
289
289
let mut substitution = TypeSubstitution {
290
- from_name : pointee_ty_ident . name ,
290
+ from_name : referent_ty_ident . name ,
291
291
to_ty : & s_ty,
292
292
rewritten : false ,
293
293
} ;
@@ -305,18 +305,18 @@ pub(crate) fn expand_deriving_smart_ptr(
305
305
}
306
306
307
307
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) ;
309
309
310
310
// Add the impl blocks for `DispatchFromDyn` and `CoerceUnsized`.
311
311
let gen_args = vec ! [ GenericArg :: Type ( alt_self_type. clone( ) ) ] ;
312
312
add_impl_block ( impl_generics. clone ( ) , sym:: DispatchFromDyn , gen_args. clone ( ) ) ;
313
313
add_impl_block ( impl_generics. clone ( ) , sym:: CoerceUnsized , gen_args) ;
314
314
}
315
315
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 {
317
317
for bound in predicates {
318
318
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 )
320
320
{
321
321
for bound in & bound. bounds {
322
322
if is_maybe_sized_bound ( bound) {
0 commit comments