diff --git a/src/test_utils.rs b/src/test_utils.rs index 9a5d674..90e4a65 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -51,3 +51,34 @@ macro_rules! concat_fmt { } ) } + +// workaround for PhantomData changing to printing type argument +pub struct MyPhantomData(core::marker::PhantomData); + +impl Copy for MyPhantomData {} + +impl Clone for MyPhantomData { + fn clone(&self) -> Self { + *self + } +} + +impl core::fmt::Debug for MyPhantomData { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + f.write_str("PhantomData") + } +} + +impl crate::PanicFmt for MyPhantomData { + type This = Self; + type Kind = crate::IsCustomType; + const PV_COUNT: usize = 1; +} + +impl MyPhantomData { + pub const NEW: Self = Self(core::marker::PhantomData); + + pub const fn to_panicvals(self, _: crate::FmtArg) -> [crate::PanicVal<'static>; 1] { + [crate::PanicVal::write_str("PhantomData")] + } +} diff --git a/tests/main_tests/derive_tests.rs b/tests/main_tests/derive_tests.rs index 413aef6..1526bcb 100644 --- a/tests/main_tests/derive_tests.rs +++ b/tests/main_tests/derive_tests.rs @@ -1,6 +1,6 @@ use const_panic::{FmtArg, PanicFmt}; -use core::marker::PhantomData; +use const_panic::test_utils::MyPhantomData; macro_rules! fmt_flatten { ($($args:tt)*) => ( @@ -181,7 +181,7 @@ fn ignored_generic_params_formatting() { { use $module::IgnoredGenericParams as IGP; - let foo = IGP(&3, PhantomData, PhantomData); + let foo = IGP(&3, MyPhantomData::NEW, MyPhantomData::NEW); assert_eq!( fmt_flatten!(FmtArg::DEBUG; IGP => foo), @@ -203,8 +203,8 @@ mod implicit_gpi { #[pfmt(ignore(A, B))] pub struct IgnoredGenericParams<'a, A, B, const X: u32, const Y: char>( pub &'a u32, - pub PhantomData, - pub PhantomData, + pub MyPhantomData, + pub MyPhantomData, ); } @@ -215,8 +215,8 @@ mod explicit_gpi { #[pfmt(ignore(A = u32, B = u64, X = 100, Y = '_'))] pub struct IgnoredGenericParams<'a, A, B, const X: u32, const Y: char>( pub &'a u32, - pub PhantomData, - pub PhantomData, + pub MyPhantomData, + pub MyPhantomData, ); } @@ -231,7 +231,7 @@ fn ignored_generic_params_and_impl_formatting() { (IgnoredAndImpl); ($ty:path) => { - let foo = $ty(&3, PhantomData, PhantomData); + let foo = $ty(&3, MyPhantomData::NEW, MyPhantomData::NEW); assert_eq!( fmt_flatten!(FmtArg::DEBUG; $ty => foo), @@ -253,6 +253,6 @@ fn ignored_generic_params_and_impl_formatting() { #[pfmt(impl<'b, G, const H: u32, const I: char> IgnoredAndImpl<'b, G, u32, H, I>)] pub struct IgnoredAndImpl<'a, A, B, const X: u32, const Y: char>( pub &'a u32, - pub PhantomData, - pub PhantomData, + pub MyPhantomData, + pub MyPhantomData, ); diff --git a/tests/main_tests/impl_panicfmt_tests.rs b/tests/main_tests/impl_panicfmt_tests.rs index 40ad927..9953dd8 100644 --- a/tests/main_tests/impl_panicfmt_tests.rs +++ b/tests/main_tests/impl_panicfmt_tests.rs @@ -1,6 +1,6 @@ use const_panic::FmtArg; -use std::marker::PhantomData; +use const_panic::test_utils::MyPhantomData; #[test] fn struct_formatting() { @@ -178,121 +178,121 @@ fn generic_parsing() { (GenericParsingB6<'_, u32, 0>); ($type_name:path) => { - let foo = $type_name(PhantomData); + let foo = $type_name(MyPhantomData::NEW); assert_eq!(trunc_fmt!(999;FmtArg::DEBUG; foo), *format!("{:?}", foo)); } } } #[derive(Debug)] -struct GenericParsing0<'a>(PhantomData<(&'a (), ())>); +struct GenericParsing0<'a>(MyPhantomData<(&'a (), ())>); #[derive(Debug)] -struct GenericParsing1<'a>(PhantomData<(&'a (), ())>); +struct GenericParsing1<'a>(MyPhantomData<(&'a (), ())>); #[derive(Debug)] -struct GenericParsing2<'a, T>(PhantomData<(&'a (), T)>); +struct GenericParsing2<'a, T>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsing3<'a, T>(PhantomData<(&'a (), T)>); +struct GenericParsing3<'a, T>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsing4<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsing4<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsing5<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsing5<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsing6<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsing6<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); const_panic::impl_panicfmt! { - struct GenericParsing0<'a,>(PhantomData<(&'a (), ())>); + struct GenericParsing0<'a,>(MyPhantomData<(&'a (), ())>); } const_panic::impl_panicfmt! { - struct GenericParsing1<'a,>(PhantomData<(&'a (), ())>); + struct GenericParsing1<'a,>(MyPhantomData<(&'a (), ())>); } const_panic::impl_panicfmt! { - struct GenericParsing2<'a, ignore T>(PhantomData<(&'a (), T)>); + struct GenericParsing2<'a, ignore T>(MyPhantomData<(&'a (), T)>); } const_panic::impl_panicfmt! { - struct GenericParsing3<'a, ignore T,>(PhantomData<(&'a (), T)>); + struct GenericParsing3<'a, ignore T,>(MyPhantomData<(&'a (), T)>); } const_panic::impl_panicfmt! { - struct GenericParsing4<'a, ignore T, const U: u32>(PhantomData<(&'a (), T)>); + struct GenericParsing4<'a, ignore T, const U: u32>(MyPhantomData<(&'a (), T)>); } const_panic::impl_panicfmt! { - struct GenericParsing5<'a, ignore(PhantomData) T, ignore const U: u32,>( - PhantomData<(&'a (), T)> + struct GenericParsing5<'a, ignore(MyPhantomData) T, ignore const U: u32,>( + MyPhantomData<(&'a (), T)> ); } const_panic::impl_panicfmt! { struct GenericParsing6<'a, ignore T, ignore(2) const U: u32,>( - PhantomData<(&'a (), T)> + MyPhantomData<(&'a (), T)> ); } #[derive(Debug)] -struct GenericParsingB0<'a>(PhantomData<(&'a (), ())>); +struct GenericParsingB0<'a>(MyPhantomData<(&'a (), ())>); #[derive(Debug)] -struct GenericParsingB1<'a>(PhantomData<(&'a (), ())>); +struct GenericParsingB1<'a>(MyPhantomData<(&'a (), ())>); #[derive(Debug)] -struct GenericParsingB2<'a, T: ?Sized>(PhantomData<(&'a (), T)>); +struct GenericParsingB2<'a, T: ?Sized>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsingB3<'a, T: ?Sized>(PhantomData<(&'a (), T)>); +struct GenericParsingB3<'a, T: ?Sized>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsingB4<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsingB4<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsingB5<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsingB5<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); #[derive(Debug)] -struct GenericParsingB6<'a, T, const U: u32>(PhantomData<(&'a (), T)>); +struct GenericParsingB6<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); const_panic::impl_panicfmt! { - struct GenericParsingB0<'a>(PhantomData<(&'a (), ())>); + struct GenericParsingB0<'a>(MyPhantomData<(&'a (), ())>); (impl['a] GenericParsingB0<'a>) } const_panic::impl_panicfmt! { - struct GenericParsingB1<'a>(PhantomData<(&'a (), ())>); + struct GenericParsingB1<'a>(MyPhantomData<(&'a (), ())>); (impl['a] GenericParsingB1<'a,> where[]) } const_panic::impl_panicfmt! { - struct GenericParsingB2<'a, ignore T>(PhantomData<(&'a (), T)>) + struct GenericParsingB2<'a, ignore T>(MyPhantomData<(&'a (), T)>) where[T: ?Sized]; (impl['a, T] GenericParsingB2<'a, T> where[T: ?Sized]) } const_panic::impl_panicfmt! { - struct GenericParsingB3<'a, ignore T,>(PhantomData<(&'a (), T)>) + struct GenericParsingB3<'a, ignore T,>(MyPhantomData<(&'a (), T)>) where[T: ?Sized]; (impl['a, T: ?Sized] GenericParsingB3<'a, T,>) } const_panic::impl_panicfmt! { - struct GenericParsingB4<'a, T, const U: u32>(PhantomData<(&'a (), T)>); + struct GenericParsingB4<'a, T, const U: u32>(MyPhantomData<(&'a (), T)>); (impl['a, const U: u32] GenericParsingB4<'a, u32, U,>) } const_panic::impl_panicfmt! { - struct GenericParsingB5<'a, ignore(PhantomData) T, ignore const U: u32,>( - PhantomData<(&'a (), T)> + struct GenericParsingB5<'a, ignore(MyPhantomData) T, ignore const U: u32,>( + MyPhantomData<(&'a (), T)> ); (impl['a, const U: u32] GenericParsingB5<'a, u32, U>) @@ -300,7 +300,7 @@ const_panic::impl_panicfmt! { const_panic::impl_panicfmt! { struct GenericParsingB6<'a, ignore T, ignore(2) const U: u32,>( - PhantomData<(&'a (), T)> + MyPhantomData<(&'a (), T)> ); (impl['a] GenericParsingB6<'a, u32, 0>)