// This file is part of ICU4X. For terms of use, please see the file // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). #![allow(unused)] use std::{borrow::Cow, marker::PhantomData}; use yoke::{Yoke, Yokeable}; use zerovec::{maps::ZeroMapKV, ule::AsULE, VarZeroVec, ZeroMap, ZeroVec}; #[derive(Yokeable)] struct StringExample { x: String, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualStringExample { x: String, } #[derive(Yokeable, Copy, Clone)] struct IntExample { x: u32, } #[derive(Yokeable, Copy, Clone)] #[yoke(prove_covariance_manually)] struct ManualIntExample { x: u32, } #[derive(Yokeable, Copy, Clone)] struct GenericsExample { x: u32, y: T, } #[derive(Yokeable, Copy, Clone)] #[yoke(prove_covariance_manually)] struct ManualGenericsExample { x: u32, y: T, } #[derive(Yokeable, Copy, Clone)] struct GenericsExampleWithDefault { x: T, y: U, } #[derive(Yokeable, Copy, Clone)] #[yoke(prove_covariance_manually)] struct ManualGenericsExampleWithDefault { x: T, y: U, } #[derive(Yokeable)] struct CowExample<'a> { x: u8, y: &'a str, z: Cow<'a, str>, w: Cow<'a, [u8]>, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualCowExample<'a> { x: u8, y: &'a str, z: Cow<'a, str>, w: Cow<'a, [u8]>, } #[derive(Yokeable)] struct ZeroVecExample<'not_a> { var: VarZeroVec<'not_a, str>, vec: ZeroVec<'not_a, u16>, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualZeroVecExample<'not_a> { var: VarZeroVec<'not_a, str>, vec: ZeroVec<'not_a, u16>, } #[derive(Yokeable)] struct ZeroVecExampleWithGenerics<'a, T: AsULE> { gen: ZeroVec<'a, T>, vec: ZeroVec<'a, u16>, bare: T, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualZeroVecExampleWithGenerics<'a, T: AsULE> { gen: ZeroVec<'a, T>, vec: ZeroVec<'a, u16>, bare: T, } // Since ZeroMap has generic parameters, the Rust compiler cannot // prove the covariance of the lifetimes. To use derive(Yokeable) // with a type such as ZeroMap, you just add the attribute // yoke(prove_covariance_manually) #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualZeroMapExample<'a> { map: ZeroMap<'a, str, u16>, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualZeroMapGenericExample<'a, T: for<'b> ZeroMapKV<'b> + ?Sized> { map: ZeroMap<'a, str, T>, } #[derive(Yokeable)] struct MaybeSizedWrap { x: T, y: Option, ignored: PhantomData, q: Q, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualMaybeSizedWrap { x: T, y: Option, ignored: PhantomData, q: Q, } // TODO(#4119): Make this example compile /* #[derive(Yokeable)] struct MaybeSizedWrapWithLifetime<'a, T, Q: ?Sized, U: ?Sized> { x: T, y: Option, ignored: &'a U, q: Q, } */ trait Trait {} impl Trait for u32 {} #[derive(Yokeable)] struct WithTraitBounds { x: T, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualWithTraitBounds { x: T, } #[derive(Yokeable)] struct WithTraitBoundsInWhere where T: Trait, { x: T, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualWithTraitBoundsInWhere where T: Trait, { x: T, } #[derive(Yokeable)] struct BoundFn<'a>(&'a (), for<'b> fn(&'b ())); #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualBoundFn<'a>(&'a (), for<'b> fn(&'b ())); #[derive(Yokeable)] struct Invariant<'a, T>(&'a mut T); #[derive(Yokeable)] struct InvariantStatic<'a> { field: Invariant<'a, &'static str>, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualInvariantStatic<'a> { field: Invariant<'a, &'static str>, } #[derive(Yokeable)] struct RawLifetime<'r#mod> { field: &'r#mod str, other: for<'r#yoke> fn(&'r#yoke ()), } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualRawLifetime<'r#mod> { field: &'r#mod str, other: for<'r#yoke> fn(&'r#yoke ()), } #[derive(Yokeable)] struct MixedRawLifetime<'r#a> { field: &'r#a &'a str, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualMixedRawLifetime<'r#a> { field: &'r#a &'a str, } #[derive(Yokeable)] struct YokeLifetime<'r#_yoke>(&'r#_yoke str, for<'yoke> fn(&'yoke ())); #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualYokeLifetime<'r#_yoke>(&'r#_yoke str, for<'yoke> fn(&'yoke ())); // TODO: make this compile // #[derive(Yokeable)] struct ConstGenerics<'a, const N: u32> { field: &'a str, } // #[derive(Yokeable)] // #[yoke(prove_covariance_manually)] struct ManualConstGenerics<'a, const N: u32> { field: &'a str, } #[derive(Yokeable)] struct Variadic<'a> { field: fn(extern "C" fn(&'a (), u32, u32, ...)), } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] struct ManualVariadic<'a> { // `fn(..)` does not implement `Yokeable`, even if the type is in fact covariant. // Thus the extra `&'a`. field: &'a fn(extern "C" fn(&'a (), u32, u32, ...)), } #[derive(Yokeable)] enum Enum { A, B, } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] enum ManualEnum { A, B, } #[derive(Yokeable)] enum Empty {} #[derive(Yokeable)] #[yoke(prove_covariance_manually)] enum ManualEmpty {} #[derive(Yokeable)] enum Uninhabited<'a> { Variant(Empty, &'a ()), } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] enum ManualUninhabited<'a> { Variant(Empty, &'a ()), } // The random extra `r#`s are intentional #[derive(Yokeable)] enum AlmostEverything<'a, T, ULE: AsULE, r#W, /*const N: u32,*/ U = usize> where W: Trait, { X(String), X2 { x: u32, }, Y(T), Gen { x: T, y: U, }, CowExample { x: u8, y: &'a str, z: Cow<'a, str>, w: Cow<'a, [u8]>, }, ZeroVec { var: VarZeroVec<'a, str>, vec: ZeroVec<'a, u16>, }, ZeroVecGen { gen: r#ZeroVec<'a, ULE>, vec: r#ZeroVec<'a, u16>, bare: T, }, Phantom(T, Option, PhantomData<&'a ()>), TraitBounds(W), BoundFn(for<'yoke> fn(&'yoke ())), RawLifetime(for<'r#_yoke> fn(&'r#_yoke ())), MixedRawLifetime(&'r#a &'a str), Variadic(fn(extern "C" fn(&'a (), u32, u32, ...))), } #[derive(Yokeable)] #[yoke(prove_covariance_manually)] enum ManualAlmostEverything< 'a, T, ULE: AsULE, r#W, Z: for<'b> ZeroMapKV<'b> + ?Sized, // const N: u32, U = usize, > where W: Trait, { X(String), X2 { x: u32, }, Y(T), Gen { x: T, y: U, }, CowExample { x: u8, y: &'a str, z: Cow<'a, str>, w: Cow<'a, [u8]>, }, ZeroVec { var: VarZeroVec<'a, str>, vec: ZeroVec<'a, u16>, }, ZeroVecGen { gen: r#ZeroVec<'a, ULE>, vec: r#ZeroVec<'a, u16>, bare: T, }, Phantom(T, Option, PhantomData<&'a ()>), TraitBounds(W), BoundFn(for<'yoke> fn(&'yoke ())), RawLifetime(for<'r#_yoke> fn(&'r#_yoke ())), MixedRawLifetime(&'r#a &'a str), Variadic(&'a fn(extern "C" fn(&'a (), u32, u32, ...))), Map(ZeroMap<'a, str, u16>, ZeroMap<'a, str, Z>), } struct AssertYokeable { string: Yoke>, int: Yoke>, gen1: Yoke, Box<[u8]>>, gen2: Yoke, Box<[u8]>>, gen_default1: Yoke, Box<[u8]>>, gen_default2: Yoke, Box<[u8]>>, cow: Yoke, Box<[u8]>>, zv: Yoke, Box<[u8]>>, zv_gen1: Yoke, Box<[u8]>>, zv_gen2: Yoke, Box<[u8]>>, maybe_sized_wrap: Yoke, Box<[u8]>>, // TODO(#4119): Make this example compile // maybe_sized_wrap_with_lt: Yoke, Box<[u8]>>, trait_bounds: Yoke, Box<[u8]>>, trait_bounds_where: Yoke, Box<[u8]>>, bound_fn: Yoke, Box<[u8]>>, invariant_static: Yoke, Box<[u8]>>, raw: Yoke, Box<[u8]>>, mixed_raw: Yoke, Box<[u8]>>, yoke_lt: Yoke, Box<[u8]>>, // const_gen: Yoke, Box<[u8]>>, variadic: Yoke, Box<[u8]>>, simple_enum: Yoke>, empty: Yoke>, uninhabited: Yoke, Box<[u8]>>, almost_everything: Yoke, Box<[u8]>>, } struct AssertYokeableManual { string: Yoke>, int: Yoke>, gen1: Yoke, Box<[u8]>>, gen2: Yoke, Box<[u8]>>, gen_default1: Yoke, Box<[u8]>>, gen_default2: Yoke, Box<[u8]>>, cow: Yoke, Box<[u8]>>, zv: Yoke, Box<[u8]>>, zv_gen1: Yoke, Box<[u8]>>, zv_gen2: Yoke, Box<[u8]>>, map: Yoke, Box<[u8]>>, map_gen1: Yoke, Box<[u8]>>, map_gen2: Yoke, Box<[u8]>>, maybe_sized_wrap: Yoke, Box<[u8]>>, trait_bounds: Yoke, Box<[u8]>>, trait_bounds_where: Yoke, Box<[u8]>>, bound_fn: Yoke, Box<[u8]>>, invariant_static: Yoke, Box<[u8]>>, raw: Yoke, Box<[u8]>>, mixed_raw: Yoke, Box<[u8]>>, yoke_lt: Yoke, Box<[u8]>>, // const_gen: Yoke, Box<[u8]>>, variadic: Yoke, Box<[u8]>>, simple_enum: Yoke>, empty: Yoke>, uninhabited: Yoke, Box<[u8]>>, almost_everything: Yoke, Box<[u8]>>, } fn main() {}