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

facet-rs / facet / 19745557542

27 Nov 2025 06:50PM UTC coverage: 55.964% (+0.4%) from 55.525%
19745557542

Pull #935

github

web-flow
Merge 1b2f8d49e into 9dec07b1e
Pull Request #935: Fix CI issues: miri guard, dead code, and feature gate

10 of 16 new or added lines in 4 files covered. (62.5%)

5 existing lines in 2 files now uncovered.

6268 of 11200 relevant lines covered (55.96%)

122.45 hits per line

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

62.88
/facet-reflect/src/partial/partial_api/maps.rs
1
use super::*;
2

3
////////////////////////////////////////////////////////////////////////////////////////////////////
4
// Maps
5
////////////////////////////////////////////////////////////////////////////////////////////////////
6
impl Partial<'_> {
7
    /// Begins a map initialization operation
8
    ///
9
    /// This initializes the map with default capacity and allows inserting key-value pairs
10
    /// It does _not_ push a new frame onto the stack.
11
    pub fn begin_map(&mut self) -> Result<&mut Self, ReflectError> {
128✔
12
        self.require_active()?;
128✔
13
        let frame = self.frames_mut().last_mut().unwrap();
128✔
14

15
        // Check tracker state before initializing
16
        match &frame.tracker {
128✔
17
            Tracker::Uninit => {
128✔
18
                // Good, will initialize below
128✔
19
            }
128✔
20
            Tracker::Init => {
21
                // Already initialized (from a previous round), just update tracker
22
                if !matches!(frame.shape.def, Def::Map(_)) {
×
23
                    return Err(ReflectError::OperationFailed {
×
24
                        shape: frame.shape,
×
25
                        operation: "begin_map can only be called on Map types",
×
26
                    });
×
27
                }
×
28
                frame.tracker = Tracker::Map {
×
29
                    is_initialized: true,
×
30
                    insert_state: MapInsertState::Idle,
×
31
                };
×
32
                return Ok(self);
×
33
            }
UNCOV
34
            Tracker::Map { is_initialized, .. } => {
×
UNCOV
35
                if *is_initialized {
×
36
                    // Already initialized, nothing to do
UNCOV
37
                    return Ok(self);
×
38
                }
×
39
            }
40
            _ => {
41
                return Err(ReflectError::UnexpectedTracker {
×
42
                    message: "begin_map called but tracker isn't Uninit, Init, or Map",
×
43
                    current_tracker: frame.tracker.kind(),
×
44
                });
×
45
            }
46
        }
47

48
        // Check that we have a Map
49
        let map_def = match &frame.shape.def {
128✔
50
            Def::Map(map_def) => map_def,
31✔
51
            _ => {
52
                return Err(ReflectError::OperationFailed {
97✔
53
                    shape: frame.shape,
97✔
54
                    operation: "begin_map can only be called on Map types",
97✔
55
                });
97✔
56
            }
57
        };
58

59
        let init_fn = map_def.vtable.init_in_place_with_capacity_fn;
31✔
60

61
        // Initialize the map with default capacity (0)
62
        unsafe {
31✔
63
            init_fn(frame.data, 0);
31✔
64
        }
31✔
65

66
        // Update tracker to Map state
67
        frame.tracker = Tracker::Map {
31✔
68
            is_initialized: true,
31✔
69
            insert_state: MapInsertState::Idle,
31✔
70
        };
31✔
71

72
        Ok(self)
31✔
73
    }
128✔
74

75
    /// Pushes a frame for the map key. After that, `set()` should be called
76
    /// (or the key should be initialized somehow) and `end()` should be called
77
    /// to pop the frame.
78
    pub fn begin_key(&mut self) -> Result<&mut Self, ReflectError> {
133✔
79
        self.require_active()?;
133✔
80
        let frame = self.frames_mut().last_mut().unwrap();
133✔
81

82
        // Check that we have a Map in Idle state
83
        let map_def = match (&frame.shape.def, &frame.tracker) {
133✔
84
            (
85
                Def::Map(map_def),
29✔
86
                Tracker::Map {
87
                    is_initialized: true,
88
                    insert_state: MapInsertState::Idle,
89
                },
90
            ) => map_def,
29✔
91
            (
92
                Def::Map(_),
93
                Tracker::Map {
94
                    insert_state: MapInsertState::PushingKey { .. },
95
                    ..
96
                },
97
            ) => {
98
                return Err(ReflectError::OperationFailed {
×
99
                    shape: frame.shape,
×
100
                    operation: "already pushing a key, call end() first",
×
101
                });
×
102
            }
103
            (
104
                Def::Map(_),
105
                Tracker::Map {
106
                    insert_state: MapInsertState::PushingValue { .. },
107
                    ..
108
                },
109
            ) => {
110
                return Err(ReflectError::OperationFailed {
×
111
                    shape: frame.shape,
×
112
                    operation: "must complete current operation before begin_key()",
×
113
                });
×
114
            }
115
            _ => {
116
                return Err(ReflectError::OperationFailed {
104✔
117
                    shape: frame.shape,
104✔
118
                    operation: "must call begin_map() before begin_key()",
104✔
119
                });
104✔
120
            }
121
        };
122

123
        // Get the key shape
124
        let key_shape = map_def.k();
29✔
125

126
        // Allocate space for the key
127
        let key_layout = match key_shape.layout.sized_layout() {
29✔
128
            Ok(layout) => layout,
29✔
129
            Err(_) => {
130
                return Err(ReflectError::Unsized {
×
131
                    shape: key_shape,
×
132
                    operation: "begin_key allocating key",
×
133
                });
×
134
            }
135
        };
136
        let key_ptr_raw: *mut u8 = unsafe { ::alloc::alloc::alloc(key_layout) };
29✔
137

138
        let Some(key_ptr_raw) = NonNull::new(key_ptr_raw) else {
29✔
139
            return Err(ReflectError::OperationFailed {
×
140
                shape: frame.shape,
×
141
                operation: "failed to allocate memory for map key",
×
142
            });
×
143
        };
144

145
        let key_ptr = PtrUninit::new(key_ptr_raw);
29✔
146

147
        // Store the key pointer in the insert state
148
        match &mut frame.tracker {
29✔
149
            Tracker::Map { insert_state, .. } => {
29✔
150
                *insert_state = MapInsertState::PushingKey {
29✔
151
                    key_ptr,
29✔
152
                    key_initialized: false,
29✔
153
                };
29✔
154
            }
29✔
155
            _ => unreachable!(),
×
156
        }
157

158
        // Push a new frame for the key
159
        self.frames_mut().push(Frame::new(
29✔
160
            PtrUninit::new(key_ptr_raw),
29✔
161
            key_shape,
29✔
162
            FrameOwnership::ManagedElsewhere, // Ownership tracked in MapInsertState
29✔
163
        ));
164

165
        Ok(self)
29✔
166
    }
133✔
167

168
    /// Pushes a frame for the map value
169
    /// Must be called after the key has been set and popped
170
    pub fn begin_value(&mut self) -> Result<&mut Self, ReflectError> {
125✔
171
        self.require_active()?;
125✔
172
        let frame = self.frames_mut().last_mut().unwrap();
124✔
173

174
        // Check that we have a Map in PushingValue state with no value_ptr yet
175
        let (map_def, key_ptr) = match (&frame.shape.def, &frame.tracker) {
124✔
176
            (
177
                Def::Map(map_def),
23✔
178
                Tracker::Map {
179
                    insert_state:
180
                        MapInsertState::PushingValue {
181
                            value_ptr: None,
182
                            key_ptr,
23✔
183
                            ..
184
                        },
185
                    ..
186
                },
187
            ) => (map_def, *key_ptr),
23✔
188
            (
189
                Def::Map(_),
190
                Tracker::Map {
191
                    insert_state:
192
                        MapInsertState::PushingValue {
193
                            value_ptr: Some(_), ..
194
                        },
195
                    ..
196
                },
197
            ) => {
198
                return Err(ReflectError::OperationFailed {
×
199
                    shape: frame.shape,
×
200
                    operation: "already pushing a value, call end() first",
×
201
                });
×
202
            }
203
            _ => {
204
                return Err(ReflectError::OperationFailed {
101✔
205
                    shape: frame.shape,
101✔
206
                    operation: "must complete key before begin_value()",
101✔
207
                });
101✔
208
            }
209
        };
210

211
        // Get the value shape
212
        let value_shape = map_def.v();
23✔
213

214
        // Allocate space for the value
215
        let value_layout = match value_shape.layout.sized_layout() {
23✔
216
            Ok(layout) => layout,
23✔
217
            Err(_) => {
218
                return Err(ReflectError::Unsized {
×
219
                    shape: value_shape,
×
220
                    operation: "begin_value allocating value",
×
221
                });
×
222
            }
223
        };
224
        let value_ptr_raw: *mut u8 = unsafe { ::alloc::alloc::alloc(value_layout) };
23✔
225

226
        let Some(value_ptr_raw) = NonNull::new(value_ptr_raw) else {
23✔
227
            return Err(ReflectError::OperationFailed {
×
228
                shape: frame.shape,
×
229
                operation: "failed to allocate memory for map value",
×
230
            });
×
231
        };
232

233
        let value_ptr = PtrUninit::new(value_ptr_raw);
23✔
234

235
        // Store the value pointer in the insert state
236
        match &mut frame.tracker {
23✔
237
            Tracker::Map { insert_state, .. } => {
23✔
238
                *insert_state = MapInsertState::PushingValue {
23✔
239
                    key_ptr,
23✔
240
                    value_ptr: Some(value_ptr),
23✔
241
                    value_initialized: false,
23✔
242
                };
23✔
243
            }
23✔
244
            _ => unreachable!(),
×
245
        }
246

247
        // Push a new frame for the value
248
        self.frames_mut().push(Frame::new(
23✔
249
            value_ptr,
23✔
250
            value_shape,
23✔
251
            FrameOwnership::ManagedElsewhere, // Ownership tracked in MapInsertState
23✔
252
        ));
253

254
        Ok(self)
23✔
255
    }
125✔
256
}
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