Skip to content

Commit

Permalink
Fixed nightly tests
Browse files Browse the repository at this point in the history
Had to define custom PhantomData clone, because PhantomData's
Debug impl outputs the type argument in nightly.
  • Loading branch information
rodrimati1992 committed Oct 10, 2022
1 parent f6bd73e commit d432d56
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 41 deletions.
31 changes: 31 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,34 @@ macro_rules! concat_fmt {
}
)
}

// workaround for PhantomData changing to printing type argument
pub struct MyPhantomData<T: ?Sized>(core::marker::PhantomData<T>);

impl<T: ?Sized> Copy for MyPhantomData<T> {}

impl<T: ?Sized> Clone for MyPhantomData<T> {
fn clone(&self) -> Self {
*self
}
}

impl<T: ?Sized> core::fmt::Debug for MyPhantomData<T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
f.write_str("PhantomData")
}
}

impl<T: ?Sized> crate::PanicFmt for MyPhantomData<T> {
type This = Self;
type Kind = crate::IsCustomType;
const PV_COUNT: usize = 1;
}

impl<T: ?Sized> MyPhantomData<T> {
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")]
}
}
18 changes: 9 additions & 9 deletions tests/main_tests/derive_tests.rs
Original file line number Diff line number Diff line change
@@ -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)*) => (
Expand Down Expand Up @@ -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<NoFmt, NoFmt, 10, 'c'> => foo),
Expand All @@ -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<A>,
pub PhantomData<B>,
pub MyPhantomData<A>,
pub MyPhantomData<B>,
);
}

Expand All @@ -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<A>,
pub PhantomData<B>,
pub MyPhantomData<A>,
pub MyPhantomData<B>,
);
}

Expand All @@ -231,7 +231,7 @@ fn ignored_generic_params_and_impl_formatting() {
(IgnoredAndImpl<i16, u32, 13, 'Y'>);
($ty:path) =>
{
let foo = $ty(&3, PhantomData, PhantomData);
let foo = $ty(&3, MyPhantomData::NEW, MyPhantomData::NEW);

assert_eq!(
fmt_flatten!(FmtArg::DEBUG; $ty => foo),
Expand All @@ -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<A>,
pub PhantomData<B>,
pub MyPhantomData<A>,
pub MyPhantomData<B>,
);
64 changes: 32 additions & 32 deletions tests/main_tests/impl_panicfmt_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use const_panic::FmtArg;

use std::marker::PhantomData;
use const_panic::test_utils::MyPhantomData;

#[test]
fn struct_formatting() {
Expand Down Expand Up @@ -178,129 +178,129 @@ 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<u8>) T, ignore const U: u32,>(
PhantomData<(&'a (), T)>
struct GenericParsing5<'a, ignore(MyPhantomData<u8>) 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<u8>) T, ignore const U: u32,>(
PhantomData<(&'a (), T)>
struct GenericParsingB5<'a, ignore(MyPhantomData<u8>) T, ignore const U: u32,>(
MyPhantomData<(&'a (), T)>
);

(impl['a, const U: u32] GenericParsingB5<'a, u32, U>)
}

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>)
Expand Down

0 comments on commit d432d56

Please sign in to comment.