diff --git a/src/main_trait.rs b/src/main_trait.rs index f2a32b8..2c45296 100644 --- a/src/main_trait.rs +++ b/src/main_trait.rs @@ -75,6 +75,7 @@ fn gen_dummy_impl_from_inherent_impl(inherent_impl: &ItemImpl) -> syn::ItemImpl let mut main_trait_impl = inherent_impl.clone(); main_trait_impl.attrs = Vec::new(); + main_trait_impl.generics = syn::Generics::default(); main_trait_impl .items .iter_mut() diff --git a/tests/disjoint_inherent_impl.rs b/tests/disjoint_inherent_impl.rs index 08a6901..8c5b04b 100644 --- a/tests/disjoint_inherent_impl.rs +++ b/tests/disjoint_inherent_impl.rs @@ -1,66 +1,91 @@ -//use disjoint_impls::disjoint_impls; -// -//pub trait Dispatch { -// type Group; -//} -// -//pub enum GroupA {} -//impl Dispatch for String { -// type Group = GroupA; -//} -//impl Dispatch for Vec { -// type Group = GroupA; -//} -// -//pub enum GroupB {} -//impl Dispatch for i32 { -// type Group = GroupB; -//} -//impl Dispatch for u32 { -// type Group = GroupB; -//} -// -//pub struct Wrapper<'a, T, const N: usize>(&'a T); -// -//disjoint_impls! { -// impl Wrapper<'_, T, 12> where T: Dispatch + Dispatch { -// pub const NAME: &'static str = "1st Blanket A"; -// } -// impl Wrapper<'_, T, 12> where T: Dispatch + Dispatch { -// pub const NAME: &'static str = "1st Blanket B"; -// } -// -// impl + Dispatch> Wrapper<'_, T, 14> { -// pub const NAME: &'static str = "2nd Blanket A"; -// } -// impl + Dispatch> Wrapper<'_, T, 14> { -// pub const NAME: &'static str = "2nd Blanket B"; -// } -//} -// -// -//const _: () = { -// pub trait _Wrapper0<_0: ?Sized> { -// const NAME: &'static str; -// } -// -// impl<_2> _Wrapper0 for Wrapper<'_, _2, 12> where _2: Dispatch + Dispatch { -// const NAME: &'static str = "Blanket A"; -// } -// impl<_2> _Wrapper0 for Wrapper<'_, _2, 12> where _2: Dispatch { -// const NAME: &'static str = "Blanket B"; -// } -// -// impl<_2> Wrapper<'_, _2, 12> where _2: Dispatch, Self: _Wrapper0<<_2 as Dispatch>::Group> { -// pub const NAME: &'static str = ::Group>>::NAME; -// } -//}; -// -// -//#[test] -//fn disjoint_inherent_impl() { -// assert_eq!("Blanket A", >::NAME); -// assert_eq!("Blanket A", , 12>>::NAME); -// assert_eq!("Blanket B", >::NAME); -// assert_eq!("Blanket B", >::NAME); -//} +use disjoint_impls::disjoint_impls; + +pub trait Dispatch { + type Group; +} + +pub trait A {} +pub trait B {} + +pub enum GroupA {} +impl A for String {} +impl Dispatch for String { + type Group = GroupA; +} +impl A for Vec {} +impl Dispatch for Vec { + type Group = GroupA; +} + +pub enum GroupB {} +impl B for i32 {} +impl Dispatch for i32 { + type Group = GroupB; +} +impl B for u32 {} +impl Dispatch for u32 { + type Group = GroupB; +} + +pub struct Wrapper<'a, T, const N: usize>(&'a T); + +disjoint_impls! { + impl Wrapper<'_, T, 12> where T: Dispatch + Dispatch { + pub const NAME: &'static str = "1st Blanket A"; + } + impl Wrapper<'_, T, 12> where T: Dispatch + Dispatch + B { + pub const NAME: &'static str = "1st Blanket B"; + } + + impl + Dispatch> Wrapper<'_, T, 14> { + pub const NAME: &'static str = "2nd Blanket A"; + } + impl + Dispatch> Wrapper<'_, T, 14> { + pub const NAME: &'static str = "2nd Blanket B"; + } +} + +/* +const _: () = { + pub trait _Wrapper0<_0: ?Sized> { + const NAME: &'static str; + } + pub trait _Wrapper1<_0: ?Sized> { + const NAME: &'static str; + } + + impl<_0: A> _Wrapper0 for Wrapper<'_, _0, 12> where _0: Dispatch + Dispatch { + const NAME: &'static str = "1st Blanket A"; + } + impl<_0> _Wrapper0 for Wrapper<'_, _0, 12> where _0: Dispatch + Dispatch + B { + const NAME: &'static str = "1st Blanket B"; + } + + impl<_0: Dispatch + Dispatch> _Wrapper1 for Wrapper<'_, _0, 14> { + const NAME: &'static str = "2nd Blanket A"; + } + impl<_0: Dispatch + Dispatch> _Wrapper1 for Wrapper<'_, _0, 14> { + const NAME: &'static str = "2nd Blanket B"; + } + + impl<_0> Wrapper<'_, _0, 12> where _0: Dispatch, Self: _Wrapper0<<_0 as Dispatch>::Group> { + pub const NAME: &'static str = ::Group>>::NAME; + } + impl<_0> Wrapper<'_, _0, 14> where _0: Dispatch, Self: _Wrapper1<<_0 as Dispatch>::Group> { + pub const NAME: &'static str = ::Group>>::NAME; + } +}; +*/ + +#[test] +fn disjoint_inherent_impl() { + assert_eq!("1st Blanket A", >::NAME); + assert_eq!("1st Blanket A", , 12>>::NAME); + assert_eq!("1st Blanket B", >::NAME); + assert_eq!("1st Blanket B", >::NAME); + + assert_eq!("2nd Blanket A", >::NAME); + assert_eq!("2nd Blanket A", , 14>>::NAME); + assert_eq!("2nd Blanket B", >::NAME); + assert_eq!("2nd Blanket B", >::NAME); +}