From acdcf237af76f1ffb101e7bf95241d0b4dcd2b48 Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Thu, 13 Jun 2024 10:28:09 -0400 Subject: [PATCH] Make FieldOffset covariant with the field type The documentation states: "A pointer-to-member can be thought of as a function from `&T` to `&U` with matching lifetimes". This updates the PhantomData field to better reflect that statement. Importantly, this removes the `U:` constraints on auto trait impls, making e.g. `FieldOffset: Sync` even if `U: !Sync`. --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b0a12c7..a93fa11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,12 +52,12 @@ pub struct FieldOffset( /// of.apply(foo) /// } /// ``` - PhantomData<(PhantomContra, U, PinFlag)>, + PhantomData<(PhantomFn, PinFlag)>, ); /// `fn` cannot appear directly in a type that need to be const. /// Workaround that with an indirection -struct PhantomContra(fn(T)); +struct PhantomFn(fn(T) -> U); /// Type that can be used in the `PinFlag` parameter of `FieldOffset` to specify that /// this projection is valid on Pin types.