Skip to content

Commit

Permalink
Deprecated {TypeCmp, TypeNe}::with_any
Browse files Browse the repository at this point in the history
Deprecated because of fallout from:
rust-lang/rust#97156
`TypeId::of::<L>() != TypeId::of::<R>()` does not imply `L != R`

Removed all uses of `with_any` constructor outside of docs/tests specific to it.
  • Loading branch information
rodrimati1992 committed Jan 6, 2024
1 parent 9a209e3 commit 76f3e6b
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 128 deletions.
29 changes: 21 additions & 8 deletions src/methods/zipping_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,14 @@ declare_zip_items!{
/// This example shows all permutations of argument and return types.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_ne};
/// use typewit::methods::zip2;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, B), (B, A)> = zip2(eq, eq.flip());
Expand Down Expand Up @@ -346,10 +350,14 @@ declare_zip_items!{
/// This example shows basic usage.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq, type_ne};
/// use typewit::methods::zip3;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, B, i64), (B, A, i64)> = zip3(eq, eq.flip(), type_eq::<i64>());
Expand Down Expand Up @@ -391,10 +399,14 @@ declare_zip_items!{
/// This example shows basic usage.
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_eq, type_ne};
/// use typewit::methods::zip4;
///
/// with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
/// with::<u8, u8, bool, u16, u32>(
/// TypeEq::NEW,
/// type_ne!(u8, bool),
/// TypeCmp::Ne(type_ne!(u16, u32)),
/// );
///
/// const fn with<A, B, C, D, E>(eq: TypeEq<A, B>, ne: TypeNe<B, C>, cmp: TypeCmp<D, E>) {
/// let _: TypeEq<(A, u64, B, i64), (B, u64, A, i64)> =
Expand Down Expand Up @@ -458,11 +470,12 @@ mod with_const_marker {
/// methods::in_array,
/// const_marker::Usize,
/// TypeCmp, TypeEq, TypeNe,
/// type_ne,
/// };
///
/// let eq_ty: TypeEq<i16, i16> = TypeEq::NEW;
/// let ne_ty: TypeNe<i16, u16> = TypeNe::with_any().unwrap();
/// let cmp_ty: TypeCmp<i16, u16> = TypeCmp::with_any();
/// let ne_ty: TypeNe<i16, u16> = type_ne!(i16, u16);
/// let cmp_ty: TypeCmp<i16, u16> = TypeCmp::Ne(type_ne!(i16, u16));
///
/// let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
/// let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
23 changes: 14 additions & 9 deletions src/type_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,16 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// let ne = TypeCmp::<u8, i8>::with_any();
/// assert!(matches!(ne, TypeCmp::Ne(_)));
/// ```
#[deprecated = concat!(
"fallout of `https://github.com/rust-lang/rust/issues/97156`,",
"`TypeId::of::<L>() != TypeId::of::<R>()` does not imply `L != R`"
)]
pub fn with_any() -> Self
where
L: Sized + Any,
R: Sized + Any,
{
#[allow(deprecated)]
if let Some(equal) = TypeEq::with_any() {
TypeCmp::Eq(equal)
} else if let Some(unequal) = TypeNe::with_any() {
Expand Down Expand Up @@ -179,12 +184,12 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, type_ne};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.eq(), Some(TypeEq::<u8, u8>{..})));
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.eq(), None::<TypeEq<u8, i8>>));
/// ```
pub const fn eq(self) -> Option<TypeEq<L, R>> {
Expand All @@ -199,12 +204,12 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeEq, TypeNe};
/// use typewit::{TypeCmp, TypeEq, TypeNe, type_ne};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.ne(), None::<TypeNe<u8, u8>>));
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.ne(), Some(TypeNe::<u8, i8>{..})));
/// ```
pub const fn ne(self) -> Option<TypeNe<L, R>> {
Expand Down Expand Up @@ -259,7 +264,7 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// ```rust
/// use typewit::{TypeCmp, TypeEq};
///
/// let eq: TypeCmp<u8, u8> = TypeCmp::with_any();
/// let eq: TypeCmp<u8, u8> = TypeCmp::Eq(TypeEq::NEW);
/// assert!(matches!(eq.unwrap_eq(), TypeEq::<u8, u8>{..}));
/// ```
#[track_caller]
Expand All @@ -279,9 +284,9 @@ impl<L: ?Sized, R: ?Sized> TypeCmp<L, R> {
/// # Example
///
/// ```rust
/// use typewit::{TypeCmp, TypeNe};
/// use typewit::{TypeCmp, TypeNe, type_ne};
///
/// let ne = TypeCmp::<u8, i8>::with_any();
/// let ne = TypeCmp::Ne(type_ne!(u8, i8));
/// assert!(matches!(ne.unwrap_ne(), TypeNe::<u8, i8>{..}));
/// ```
#[track_caller]
Expand Down
5 changes: 3 additions & 2 deletions src/type_cmp/extra_type_cmp_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,11 @@ impl<L, R> TypeCmp<L, R> {
/// use typewit::{
/// const_marker::Usize,
/// TypeCmp, TypeEq, TypeNe,
/// type_ne,
/// };
///
/// let cmp_eq_ty: TypeCmp<i32, i32> = TypeCmp::with_any();
/// let cmp_ne_ty: TypeCmp<i64, u64> = TypeCmp::with_any();
/// let cmp_eq_ty: TypeCmp<i32, i32> = TypeCmp::Eq(TypeEq::NEW);
/// let cmp_ne_ty: TypeCmp<i64, u64> = TypeCmp::Ne(type_ne!(i64, u64));
///
/// let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
/// let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
6 changes: 5 additions & 1 deletion src/type_ne_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ impl<L: ?Sized, R: ?Sized> TypeNe<L, R> {
/// assert!(TypeNe::<u8, u8>::with_any().is_none());
///
/// ```
#[deprecated = concat!(
"fallout of `https://github.com/rust-lang/rust/issues/97156`,",
"`TypeId::of::<L>() != TypeId::of::<R>()` does not imply `L != R`"
)]
pub fn with_any() -> Option<Self>
where
L: Sized + Any,
R: Sized + Any,
{
if TypeId::of::<L>() != TypeId::of::<R>() {
// SAFETY: the two TypeIds compare unequal, so L != R
// SAFETY: unsound for the deprecated reason
unsafe { Some(TypeNe::new_unchecked()) }
} else {
None
Expand Down
24 changes: 14 additions & 10 deletions tests/misc_tests/generic_fns_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use typewit::{
TypeCmp,
TypeEq,
TypeNe,
type_eq,
type_eq, type_ne,
};

use crate::misc_tests::test_utils::assertm;
Expand Down Expand Up @@ -50,9 +50,9 @@ fn zip2_test() {

constness::<u8, u8, bool, u32, u32, u64>(
TypeEq::NEW,
TypeNe::with_any().unwrap(),
TypeCmp::with_any(),
TypeCmp::with_any(),
type_ne!(u8, bool),
TypeCmp::Eq(TypeEq::NEW),
TypeCmp::Ne(type_ne!(u32, u64)),
);
}

Expand Down Expand Up @@ -101,9 +101,9 @@ fn zip3_test() {
constness::<u8, u8, u8, bool, u32, u32, u64>(
TypeEq::NEW,
TypeEq::NEW,
TypeNe::with_any().unwrap(),
TypeCmp::with_any(),
TypeCmp::with_any(),
type_ne!(u8, bool),
TypeCmp::Eq(TypeEq::NEW),
TypeCmp::Ne(type_ne!(u32, u64)),
);
}

Expand All @@ -117,7 +117,11 @@ fn test_zip4() {
let _: TypeCmp<(D, A, B, A), (E, B, A, B)> = zip4(cmp, eq, eq.flip(), eq);
}

with::<u8, u8, bool, u16, u32>(TypeEq::NEW, TypeNe::with_any().unwrap(), TypeCmp::with_any());
with::<u8, u8, bool, u16, u32>(
TypeEq::NEW,
type_ne!(u8, bool),
TypeCmp::Ne(type_ne!(u16, u32)),
);
}

#[test]
Expand All @@ -128,8 +132,8 @@ fn test_in_array() {
};

let eq_ty: TypeEq<i16, i16> = TypeEq::NEW;
let ne_ty: TypeNe<i16, u16> = TypeNe::with_any().unwrap();
let cmp_ty: TypeCmp<i16, u16> = TypeCmp::with_any();
let ne_ty: TypeNe<i16, u16> = type_ne!(i16, u16);
let cmp_ty: TypeCmp<i16, u16> = TypeCmp::Ne(type_ne!(i16, u16));

let eq_len: TypeEq<Usize<0>, Usize<0>> = TypeEq::NEW;
let ne_len: TypeNe<Usize<1>, Usize<2>> = Usize.equals(Usize).unwrap_ne();
Expand Down
Loading

0 comments on commit 76f3e6b

Please sign in to comment.