//! Tests of the tag module's API. //! //! The tag module is all type level constructs so the tests in //! this module may look very strange. /* use std::{ cell::UnsafeCell, marker::{PhantomData, PhantomPinned}, panic::{RefUnwindSafe, UnwindSafe}, }; use supply::{lt_list::LtTagOf, tag::*, Lt1, LtList}; #[allow(unused)] struct NoAuto<'a>( PhantomData<(*const u8, PhantomPinned, &'a mut u8, UnsafeCell)>, str, ); // Tagged const _: () = { #[allow(unused)] struct Test<'a>(NoAuto<'a>); impl<'a> Tagged for Test<'a> { type Tag = Static>; type LifetimesTag = LtTagOf>; } fn with_t() { // Tag always implements Sized and 'static. fn assert_assoc() {} assert_assoc::(); } }; // TagOf const _: () = { #[allow(unused)] struct Test<'a>(NoAuto<'a>); impl<'a> Tagged for Test<'a> { type Tag = Static>; type LifetimesTag = LtTagOf>; } fn with_t() { // Check that TagOf always gives the associated type. fn assert_ty, U: ?Sized>() {} assert_ty::>(); } }; // MaybeSizedTag const _: () = { #[allow(unused)] struct Test(PhantomData>); impl<'a, L: LtList> MaybeSizedTag> for Test { type Reified = NoAuto<'a>; } impl Tagged for Test { type Tag = Test; } // Check that the super traits are correct. trait AssertSuper: 'static {} #[allow(clippy::needless_maybe_sized)] impl> AssertSuper for T {} // Check that Reified is ?Sized. fn with_t, L: LtList>() { { trait AmbiguousIfImpl { fn some_item() {} } impl AmbiguousIfImpl<()> for T {} { struct Invalid; impl AmbiguousIfImpl for T {} } let _ = >::some_item; } } }; // Tag const _: () = { #[allow(unused)] struct Test(PhantomData>); impl<'a, L: LtList> MaybeSizedTag> for Test { type Reified = PhantomData>; } impl Tagged for Test { type Tag = Test; } // Check that implementing MaybeSizedTag automatically gives Tag. fn with_l() { fn assert_tag<'a, T: Tag>, L: LtList>() {} assert_tag::() } // Check that SizedReified and Reified are Sized. fn with_t, L: LtList>() { fn assert_sized + MaybeSizedTag, L: LtList>() where T::Reified: Sized, T::SizedReified: Sized, { } assert_sized::(); } }; // Static const _: () = { fn _with_t() { // Static always implements all the auto traits. fn assert_auto() {} assert_auto::>(); } fn _with_static_t() { // Static's tag is always itself. fn assert_tagged>() {} assert_tagged::>(); // Static's reified type is always it's generic. fn assert_tag() where T: MaybeSizedTag, { } assert_tag::, L, T>(); } }; // AddLt const _: () = { fn _with_t() { // AddLt always implements all the auto traits. fn assert_auto() {} assert_auto::>(); } fn _with_tagged_t() { // AddLt's tag is itself with the generic swapped for the tagged one. fn assert_tagged, U>() {} assert_tagged::, AddLt>(); } #[allow(clippy::extra_unused_lifetimes)] fn _with_tag<'a, T: MaybeSizedTag, L: LtList>() { // AddLt's reified type is always the same as it's generic's. // It also adds a lifetime to L. fn assert_tag() where T: MaybeSizedTag, { } assert_tag::, Lt1<'a, L>, T::Reified>(); } }; // Ref const _: () = { fn _with_t() { // Ref always implements all the auto traits. fn assert_auto() {} assert_auto::>(); } fn _with_tagged_t() { // Ref's tag is itself with the generic swapped for the tagged one. fn assert_tagged, U>() {} assert_tagged::, Ref>(); } fn _with_tag<'a, T: MaybeSizedTag, L: LtList>>() where T::Reified: 'a, { // Refs's reified type is always a borrow with the first lifetime. fn assert_tag<'a, T, L: LtList>, U: ?Sized + 'a>() where T: MaybeSizedTag, { } assert_tag::, L, T::Reified>(); } }; // StaticRef const _: () = { fn _with_t() { // StaticRef always implements all the auto traits. fn assert_auto() {} assert_auto::>(); } fn _with_tagged_t() { // StaticRef's tag is itself with the generic swapped for the tagged one. fn assert_tagged, U>() {} assert_tagged::, StaticRef>(); } fn _with_tag, L: LtList>() where T::Reified: 'static, { // StaticRef's reified type is always a borrow with the static lifetime. fn assert_tag() where T: MaybeSizedTag, { } assert_tag::, L, T::Reified>(); } }; // Mut const _: () = { fn _with_t() { // Mut always implements all the auto traits. fn assert_auto() {} assert_auto::>(); } fn _with_tagged_t() { // Mut's tag is itself with the generic swapped for the tagged one. fn assert_tagged, U>() {} assert_tagged::, Mut>(); } fn _with_tag<'a, T: MaybeSizedTag, L: LtList>>() where T::Reified: 'a, { // Mut's reified type is always a borrow with the first lifetime. fn assert_tag<'a, T, L: LtList>, U: ?Sized + 'a>() where T: MaybeSizedTag, { } assert_tag::, L, T::Reified>(); } }; // Check that NoAuto doesn't implement any of the auto traits. const _: () = { trait AmbiguousIfImpl { fn some_item() {} } impl AmbiguousIfImpl<()> for T {} { struct Invalid; impl AmbiguousIfImpl for T {} } { struct Invalid; impl AmbiguousIfImpl for T {} } { struct Invalid; impl AmbiguousIfImpl for T {} } { struct Invalid; impl AmbiguousIfImpl for T {} } { struct Invalid; impl AmbiguousIfImpl for T {} } { struct Invalid; impl AmbiguousIfImpl for T {} } let _ = >::some_item; }; */