• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 16050896782

03 Jul 2025 12:50PM UTC coverage: 58.747% (+0.1%) from 58.637%
16050896782

push

github

fasterthanlime
Manual impls for reference types

Replace pointer implementations with manual implementations, and
introduce new reference impls, so we can have concrete methods for &str,
&[U], etc.

157 of 174 new or added lines in 3 files covered. (90.23%)

11626 of 19790 relevant lines covered (58.75%)

123.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.33
/facet-core/src/impls_core/pointer.rs
1
use core::fmt;
2

3
use crate::{
4
    Facet, MarkerTraits, PointerType, Shape, Type, TypeParam, ValuePointerType, ValueVTable,
5
};
6

7
// *const pointers
8
unsafe impl<'a, T: Facet<'a> + ?Sized> Facet<'a> for *const T {
9
    const VTABLE: &'static ValueVTable = &const {
10
        ValueVTable::builder::<Self>()
11
            .marker_traits(|| {
20✔
12
                let mut marker_traits = MarkerTraits::EQ
20✔
13
                    .union(MarkerTraits::COPY)
20✔
14
                    .union(MarkerTraits::UNPIN);
20✔
15

16
                if T::SHAPE
20✔
17
                    .vtable
20✔
18
                    .marker_traits()
20✔
19
                    .contains(MarkerTraits::REF_UNWIND_SAFE)
20✔
20
                {
18✔
21
                    marker_traits = marker_traits
18✔
22
                        .union(MarkerTraits::UNWIND_SAFE)
18✔
23
                        .union(MarkerTraits::REF_UNWIND_SAFE);
18✔
24
                }
18✔
25

26
                marker_traits
20✔
27
            })
20✔
28
            .debug(|| Some(fmt::Debug::fmt))
28✔
29
            .clone_into(|| Some(|src, dst| unsafe { dst.put(*src) }))
4✔
30
            .type_name(|f, opts| {
12✔
31
                if let Some(opts) = opts.for_children() {
12✔
32
                    write!(f, "*const ")?;
12✔
33
                    (T::VTABLE.type_name())(f, opts)
12✔
34
                } else {
NEW
35
                    write!(f, "*const ⋯")
×
36
                }
37
            })
12✔
38
            .build()
39
    };
40

41
    const SHAPE: &'static Shape<'static> = &const {
42
        Shape::builder_for_sized::<Self>()
43
            .inner(|| T::SHAPE)
44
            .type_identifier("*const _")
45
            .type_params(&[TypeParam {
46
                name: "T",
47
                shape: || T::SHAPE,
48
            }])
49
            .ty({
50
                let is_wide = ::core::mem::size_of::<Self>() != ::core::mem::size_of::<*const ()>();
51
                let vpt = ValuePointerType {
52
                    mutable: false,
53
                    wide: is_wide,
54
                    target: || T::SHAPE,
55
                };
56

57
                Type::Pointer(PointerType::Raw(vpt))
58
            })
59
            .build()
60
    };
61
}
62

63
// *mut pointers
64
unsafe impl<'a, T: Facet<'a> + ?Sized> Facet<'a> for *mut T {
65
    const VTABLE: &'static ValueVTable = &const {
66
        ValueVTable::builder::<Self>()
67
            .marker_traits(|| {
8✔
68
                let mut marker_traits = MarkerTraits::EQ
8✔
69
                    .union(MarkerTraits::COPY)
8✔
70
                    .union(MarkerTraits::UNPIN);
8✔
71

72
                if T::SHAPE
8✔
73
                    .vtable
8✔
74
                    .marker_traits()
8✔
75
                    .contains(MarkerTraits::REF_UNWIND_SAFE)
8✔
76
                {
6✔
77
                    marker_traits = marker_traits
6✔
78
                        .union(MarkerTraits::UNWIND_SAFE)
6✔
79
                        .union(MarkerTraits::REF_UNWIND_SAFE);
6✔
80
                }
6✔
81

82
                marker_traits
8✔
83
            })
8✔
84
            .debug(|| Some(fmt::Debug::fmt))
16✔
85
            .clone_into(|| Some(|src, dst| unsafe { dst.put(*src) }))
4✔
86
            .type_name(|f, opts| {
8✔
87
                if let Some(opts) = opts.for_children() {
8✔
88
                    write!(f, "*mut ")?;
8✔
89
                    (T::VTABLE.type_name())(f, opts)
8✔
90
                } else {
NEW
91
                    write!(f, "*mut ⋯")
×
92
                }
93
            })
8✔
94
            .build()
95
    };
96

97
    const SHAPE: &'static Shape<'static> = &const {
98
        Shape::builder_for_sized::<Self>()
99
            .inner(|| T::SHAPE)
100
            .type_identifier("*mut _")
101
            .type_params(&[TypeParam {
102
                name: "T",
103
                shape: || T::SHAPE,
104
            }])
105
            .ty({
106
                let is_wide = ::core::mem::size_of::<Self>() != ::core::mem::size_of::<*const ()>();
107
                let vpt = ValuePointerType {
108
                    mutable: true,
109
                    wide: is_wide,
110
                    target: || T::SHAPE,
111
                };
112

113
                Type::Pointer(PointerType::Raw(vpt))
114
            })
115
            .build()
116
    };
117
}
118

119
#[cfg(test)]
120
mod test {
121
    use core::panic::{RefUnwindSafe, UnwindSafe};
122
    use impls::impls;
123

124
    #[allow(unused)]
125
    const fn assert_impls_unwind_safe<T: UnwindSafe>() {}
×
126
    #[allow(unused)]
127
    const fn assert_impls_ref_unwind_safe<T: RefUnwindSafe>() {}
×
128

129
    #[allow(unused)]
130
    const fn ref_unwind_safe<T: RefUnwindSafe>() {
×
131
        assert_impls_unwind_safe::<&T>();
×
132
        assert_impls_ref_unwind_safe::<&T>();
×
133

134
        assert_impls_ref_unwind_safe::<&mut T>();
×
135

136
        assert_impls_unwind_safe::<*const T>();
×
137
        assert_impls_ref_unwind_safe::<*const T>();
×
138

139
        assert_impls_unwind_safe::<*mut T>();
×
140
        assert_impls_ref_unwind_safe::<*mut T>();
×
141
    }
×
142

143
    #[test]
144
    fn mut_ref_not_unwind_safe() {
1✔
145
        assert!(impls!(&mut (): !UnwindSafe));
1✔
146
    }
1✔
147
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc