@@ -270,20 +270,25 @@ The macro will expand to two implementations, one for
270
270
[ ` core::ops::CoerceUnsized ` ] and one for [ ` core::ops::DispatchFromDyn ` ] . This
271
271
is enough for a type to participate in unsizing coercions and dynamic dispatch.
272
272
273
- The derive macro will implement the traits for the type according to the
273
+ The derive macro will implement both traits for the type according to the
274
274
following procedure:
275
275
276
- - Copy all generic parameters and their bounds from the struct definition into
277
- the impl.
278
- - Add an additional type parameter ` U ` and give it a ` ?Sized ` bound.
276
+ - Copy all generic parameters from the struct definition into the impl.
277
+ - Add an additional type parameter ` U ` .
278
+ - For every trait bound declared on the trait, add it twice to the trait
279
+ implementation. Once exactly as written, and once with every instance of the
280
+ ` #[pointee] ` parameter replaced with ` U ` .
279
281
- Add an additional ` Unsize<U> ` bound to the ` #[pointee] ` type parameter.
280
- - The generic parameter of the traits being implemented will be ` Self ` , except
282
+ - The generic parameter of the trait being implemented will be ` Self ` , except
281
283
that the ` #[pointee] ` type parameter is replaced with ` U ` .
282
284
283
285
Given the following example code:
284
286
``` rust
285
287
#[derive(SmartPointer )]
286
- struct MySmartPointer <'a , #[pointee] T : ? Sized , A >{
288
+ struct MySmartPointer <'a , #[pointee] T , A >
289
+ where
290
+ T : ? Sized + SomeTrait <T >,
291
+ {
287
292
ptr : & 'a T ,
288
293
phantom : PhantomData <A >,
289
294
}
@@ -295,15 +300,17 @@ we'll get the following expansion:
295
300
#[automatically_derived]
296
301
impl <'a , T , A , U > :: core :: ops :: CoerceUnsized <MySmartPointer <'a , U , A >> for MySmartPointer <'a , T , A >
297
302
where
298
- T : ? Sized + :: core :: marker :: Unsize <U >,
299
- U : ? :: core :: marker :: Sized ,
303
+ T : ? Sized + SomeTrait <T >,
304
+ U : ? Sized + SomeTrait <U >,
305
+ T : :: core :: marker :: Unsize <U >,
300
306
{}
301
307
302
308
#[automatically_derived]
303
309
impl <'a , T , A , U > :: core :: ops :: DispatchFromDyn <MySmartPointer <'a , U , A >> for MySmartPointer <'a , T , A >
304
310
where
305
- T : ? Sized + :: core :: marker :: Unsize <U >,
306
- U : ? :: core :: marker :: Sized ,
311
+ T : ? Sized + SomeTrait <T >,
312
+ U : ? Sized + SomeTrait <U >,
313
+ T : :: core :: marker :: Unsize <U >,
307
314
{}
308
315
```
309
316
0 commit comments