Problem with GATs?

We're trying to do this:

/// Allows working with holders to `UnsafeCell`.
///
/// # Example
///
/// ```rust
/// #![feature(generic_associated_types)]
/// #![feature(pin_macro)]
///
/// use core::cell::UnsafeCell;
/// use core::pin::pin;
/// 
/// use selfref::Holder;
/// use selfref::SelfRef;
/// use selfref::new_with_closure;
/// use selfref::opaque;
/// use selfref::operate_in_closure;
///
/// #[derive(Default)]
/// struct Foo<'a> {
///     foo: Option<&'a UnsafeCell<Foo<'a>>>,
/// }
/// impl<'a> SelfRef<'a> for Foo<'a> {}
///
/// struct FooKey;
/// opaque! {
///     impl Opaque for FooKey {
///         type Kind<'a> = UnsafeCell<Foo<'a>>;
///     }
/// }
///
/// fn main() {
///     let holder = pin!(Holder::<'_, FooKey>::new_with(
///         new_with_closure::<FooKey, _>(|foo| UnsafeCell::default())
///     ));
///     // Actually making our Foo refer to itself.
///     holder.as_ref().operate_in(
///         operate_in_closure::<FooKey, _, _>(|foo| {
///             unsafe {
///                 (*foo.get()).foo = Some(foo.get_ref());
///             }
///         })
///     );
/// }
/// ```
impl<'a, T: SelfRef<'a>> SelfRef<'a> for core::cell::UnsafeCell<T> {}

but it fails with:

---- src/lib.rs - core::cell::UnsafeCell<T> (line 568) stdout ----
error[E0277]: the trait bound `UnsafeCell<Foo<'a>>: SelfRef<'a>` is not satisfied
   --> src/lib.rs:590:25
    |
24  |         type Kind<'a> = UnsafeCell<Foo<'a>>;
    |                         ^^^^^^^^^^^^^^^^^^^ the trait `SelfRef<'a>` is not implemented for `UnsafeCell<Foo<'a>>`
    |
    = help: the trait `SelfRef<'a>` is implemented for `Foo<'a>`
note: required by a bound in `selfref::Opaque::Kind`
   --> /home/soniex2/.cache/cargo/target/package/selfref-0.1.1/src/lib.rs:141:20
    |
141 |     type Kind<'a>: SelfRef<'a> where Self: 'a;
    |                    ^^^^^^^^^^^ required by this bound in `selfref::Opaque::Kind`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
Couldn't compile the test.

Oh nvm so a newer nightly fixes it. Weird!

1 Like