1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use crate::{FmtArg, PanicFmt, PanicVal};

use core::{
    marker::{PhantomData, PhantomPinned},
    ptr::NonNull,
};

use core as std;

macro_rules! ptr_impls {
    ($ty:ty) => {
        primitive_static_panicfmt! {
            fn[T: ?Sized](&self: $ty, _f) {
                PanicVal::write_str("<pointer>")
            }
        }
    };
}

ptr_impls! {*const T}

ptr_impls! {*mut T}

ptr_impls! {NonNull<T>}

impl_for_option! {
    (for[T], 'static, NonNull<T>, NonNull<T>)
}

primitive_static_panicfmt! {
    fn[T: ?Sized](&self: PhantomData<T>, _f) {
        PanicVal::write_str("PhantomData")
    }
}

primitive_static_panicfmt! {
    fn[](&self: PhantomPinned, _f) {
        PanicVal::write_str("PhantomPinned")
    }
}

primitive_static_panicfmt! {
    fn[](&self: (), _f) {
        PanicVal::write_str("()")
    }
}

impl_for_option! {
    (for[], 'static, core::cmp::Ordering, core::cmp::Ordering)
}
primitive_static_panicfmt! {
    fn[](&self: std::cmp::Ordering, _f) {
        let v = match self.0 {
            std::cmp::Ordering::Less => "Less",
            std::cmp::Ordering::Equal => "Equal",
            std::cmp::Ordering::Greater => "Greater",
        };
        PanicVal::write_str(v)
    }
}

primitive_static_panicfmt! {
    fn[](&self: std::sync::atomic::Ordering, _f) {
        use std::sync::atomic::Ordering;
        let v = match self.0 {
            Ordering::Relaxed => "Relaxed",
            Ordering::Release => "Release",
            Ordering::Acquire => "Acquire",
            Ordering::AcqRel => "AcqRel",
            Ordering::SeqCst => "SeqCst",
            _ => "<std::sync::atomic::Ordering>",
        };
        PanicVal::write_str(v)
    }
}