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

facet-rs / facet / 14551260122

19 Apr 2025 05:16PM UTC coverage: 45.913% (+1.6%) from 44.351%
14551260122

Pull #307

github

web-flow
Merge 48bb5180a into 69cb0f3ca
Pull Request #307: Impl `Facet` for `Rc<T>`

331 of 395 new or added lines in 3 files covered. (83.8%)

7 existing lines in 1 file now uncovered.

5319 of 11585 relevant lines covered (45.91%)

48.81 hits per line

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

90.1
/facet-core/src/impls_alloc/smartptr.rs
1
use core::alloc::Layout;
2

3
use crate::{
4
    ConstTypeId, Def, Facet, KnownSmartPointer, Opaque, PtrConst, SmartPointerDef,
5
    SmartPointerFlags, SmartPointerVTable, value_vtable,
6
};
7

8
unsafe impl<T: Facet> Facet for alloc::sync::Arc<T> {
9
    const SHAPE: &'static crate::Shape = &const {
10
        crate::Shape::builder()
11
            .id(ConstTypeId::of::<Self>())
12
            .layout(Layout::new::<Self>())
13
            .type_params(&[crate::TypeParam {
14
                name: "T",
15
                shape: || T::SHAPE,
2✔
16
            }])
17
            .def(Def::SmartPointer(
18
                SmartPointerDef::builder()
19
                    .pointee(T::SHAPE)
20
                    .flags(SmartPointerFlags::ATOMIC)
21
                    .known(KnownSmartPointer::Arc)
22
                    .weak(|| <alloc::sync::Weak<T> as Facet>::SHAPE)
×
23
                    .vtable(
24
                        &const {
25
                            SmartPointerVTable::builder()
26
                                .borrow_fn(|this| {
2✔
27
                                    let ptr = Self::as_ptr(unsafe { this.get() });
2✔
28
                                    PtrConst::new(ptr)
2✔
29
                                })
2✔
30
                                .new_into_fn(|this, ptr| {
1✔
31
                                    let t = unsafe { ptr.read::<T>() };
1✔
32
                                    let arc = alloc::sync::Arc::new(t);
1✔
33
                                    unsafe { this.put(arc) }
1✔
34
                                })
1✔
35
                                .downgrade_fn(|strong, weak| unsafe {
1✔
36
                                    weak.put(alloc::sync::Arc::downgrade(strong.get::<Self>()))
1✔
37
                                })
1✔
38
                                .build()
39
                        },
40
                    )
41
                    .build(),
42
            ))
43
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
×
44
                f,
×
45
                "Arc"
×
46
            )))
×
47
            .build()
48
    };
49
}
50

51
unsafe impl<T: Facet> Facet for alloc::sync::Weak<T> {
52
    const SHAPE: &'static crate::Shape = &const {
53
        crate::Shape::builder()
54
            .id(ConstTypeId::of::<Self>())
55
            .layout(Layout::new::<Self>())
56
            .type_params(&[crate::TypeParam {
57
                name: "T",
58
                shape: || T::SHAPE,
1✔
59
            }])
60
            .def(Def::SmartPointer(
61
                SmartPointerDef::builder()
62
                    .pointee(T::SHAPE)
63
                    .flags(SmartPointerFlags::ATOMIC.union(SmartPointerFlags::WEAK))
64
                    .known(KnownSmartPointer::ArcWeak)
65
                    .strong(|| <alloc::sync::Arc<T> as Facet>::SHAPE)
×
66
                    .vtable(
67
                        &const {
68
                            SmartPointerVTable::builder()
69
                                .upgrade_into_fn(|weak, strong| unsafe {
2✔
70
                                    Some(strong.put(weak.get::<Self>().upgrade()?))
2✔
71
                                })
2✔
72
                                .build()
73
                        },
74
                    )
75
                    .build(),
76
            ))
77
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
×
78
                f,
×
79
                "Arc"
×
80
            )))
×
81
            .build()
82
    };
83
}
84

85
unsafe impl<T> Facet for Opaque<alloc::sync::Arc<T>> {
86
    const SHAPE: &'static crate::Shape = &const {
87
        crate::Shape::builder()
88
            .id(ConstTypeId::of::<Self>())
89
            .layout(Layout::new::<Self>())
90
            .def(Def::SmartPointer(
91
                SmartPointerDef::builder()
92
                    .flags(SmartPointerFlags::ATOMIC)
93
                    .known(KnownSmartPointer::Arc)
94
                    .vtable(
95
                        &const {
96
                            SmartPointerVTable::builder()
NEW
97
                                .borrow_fn(|this| {
×
NEW
98
                                    let ptr = alloc::sync::Arc::<T>::as_ptr(unsafe { this.get() });
×
99
                                    PtrConst::new(ptr)
×
100
                                })
×
101
                                .new_into_fn(|this, ptr| {
×
102
                                    let t = unsafe { ptr.read::<T>() };
×
103
                                    let arc = alloc::sync::Arc::new(t);
×
104
                                    unsafe { this.put(arc) }
×
105
                                })
×
106
                                .build()
107
                        },
108
                    )
109
                    .build(),
110
            ))
111
            .vtable(value_vtable!(alloc::sync::Arc<T>, |f, _opts| write!(
1✔
112
                f,
1✔
113
                "Arc"
1✔
114
            )))
1✔
115
            .build()
116
    };
117
}
118

119
unsafe impl<T: Facet> Facet for alloc::rc::Rc<T> {
120
    const SHAPE: &'static crate::Shape = &const {
121
        crate::Shape::builder()
122
            .id(ConstTypeId::of::<Self>())
123
            .layout(Layout::new::<Self>())
124
            .type_params(&[crate::TypeParam {
125
                name: "T",
126
                shape: || T::SHAPE,
1✔
127
            }])
128
            .def(Def::SmartPointer(
129
                SmartPointerDef::builder()
130
                    .pointee(T::SHAPE)
131
                    .flags(SmartPointerFlags::EMPTY)
132
                    .known(KnownSmartPointer::Rc)
NEW
133
                    .weak(|| <alloc::rc::Weak<T> as Facet>::SHAPE)
×
134
                    .vtable(
135
                        &const {
136
                            SmartPointerVTable::builder()
137
                                .borrow_fn(|this| {
2✔
138
                                    let ptr = Self::as_ptr(unsafe { this.get() });
2✔
139
                                    PtrConst::new(ptr)
2✔
140
                                })
2✔
141
                                .new_into_fn(|this, ptr| {
1✔
142
                                    let t = unsafe { ptr.read::<T>() };
1✔
143
                                    let rc = alloc::rc::Rc::new(t);
1✔
144
                                    unsafe { this.put(rc) }
1✔
145
                                })
1✔
146
                                .downgrade_fn(|strong, weak| unsafe {
1✔
147
                                    weak.put(alloc::rc::Rc::downgrade(strong.get::<Self>()))
1✔
148
                                })
1✔
149
                                .build()
150
                        },
151
                    )
152
                    .build(),
153
            ))
NEW
154
            .vtable(value_vtable!(alloc::rc::Rc<T>, |f, _opts| write!(f, "Rc")))
×
155
            .build()
156
    };
157
}
158

159
unsafe impl<T: Facet> Facet for alloc::rc::Weak<T> {
160
    const SHAPE: &'static crate::Shape = &const {
161
        crate::Shape::builder()
162
            .id(ConstTypeId::of::<Self>())
163
            .layout(Layout::new::<Self>())
164
            .type_params(&[crate::TypeParam {
165
                name: "T",
NEW
166
                shape: || T::SHAPE,
×
167
            }])
168
            .def(Def::SmartPointer(
169
                SmartPointerDef::builder()
170
                    .pointee(T::SHAPE)
171
                    .flags(SmartPointerFlags::WEAK)
172
                    .known(KnownSmartPointer::RcWeak)
NEW
173
                    .strong(|| <alloc::rc::Rc<T> as Facet>::SHAPE)
×
174
                    .vtable(
175
                        &const {
176
                            SmartPointerVTable::builder()
177
                                .upgrade_into_fn(|weak, strong| unsafe {
2✔
178
                                    Some(strong.put(weak.get::<Self>().upgrade()?))
2✔
179
                                })
2✔
180
                                .build()
181
                        },
182
                    )
183
                    .build(),
184
            ))
NEW
185
            .vtable(value_vtable!(alloc::rc::Rc<T>, |f, _opts| write!(f, "Rc")))
×
186
            .build()
187
    };
188
}
189

190
unsafe impl<T> Facet for Opaque<alloc::rc::Rc<T>> {
191
    const SHAPE: &'static crate::Shape = &const {
192
        crate::Shape::builder()
193
            .id(ConstTypeId::of::<Self>())
194
            .layout(Layout::new::<Self>())
195
            .def(Def::SmartPointer(
196
                SmartPointerDef::builder()
197
                    .known(KnownSmartPointer::Rc)
198
                    .vtable(
199
                        &const {
200
                            SmartPointerVTable::builder()
NEW
201
                                .borrow_fn(|this| {
×
NEW
202
                                    let ptr = alloc::rc::Rc::<T>::as_ptr(unsafe { this.get() });
×
NEW
203
                                    PtrConst::new(ptr)
×
NEW
204
                                })
×
NEW
205
                                .new_into_fn(|this, ptr| {
×
NEW
206
                                    let t = unsafe { ptr.read::<T>() };
×
NEW
207
                                    let rc = alloc::rc::Rc::new(t);
×
NEW
208
                                    unsafe { this.put(rc) }
×
NEW
209
                                })
×
210
                                .build()
211
                        },
212
                    )
213
                    .build(),
214
            ))
NEW
215
            .vtable(value_vtable!(alloc::rc::Rc<T>, |f, _opts| write!(f, "Rc")))
×
216
            .build()
217
    };
218
}
219

220
#[cfg(test)]
221
mod tests {
222
    use alloc::rc::{Rc, Weak as RcWeak};
223
    use alloc::sync::{Arc, Weak as ArcWeak};
224
    use alloc::string::String;
225
    use core::mem::MaybeUninit;
226

227
    use super::*;
228

229
    use crate::PtrUninit;
230

231
    #[test]
232
    fn test_arc_type_params() {
1✔
233
        let [type_param_1] = <Arc<i32>>::SHAPE.type_params else {
1✔
NEW
234
            panic!("Arc<T> should only have 1 type param")
×
235
        };
236
        assert_eq!(type_param_1.shape(), i32::SHAPE);
1✔
237
    }
1✔
238

239
    #[test]
240
    fn test_arc_vtable() {
1✔
241
        facet_testhelpers::setup();
1✔
242

1✔
243
        let arc_shape = <Arc<String>>::SHAPE;
1✔
244
        let arc_def = arc_shape
1✔
245
            .def
1✔
246
            .into_smart_pointer()
1✔
247
            .expect("Arc<T> should have a smart pointer definition");
1✔
248

1✔
249
        let weak_shape = <ArcWeak<String>>::SHAPE;
1✔
250
        let weak_def = weak_shape
1✔
251
            .def
1✔
252
            .into_smart_pointer()
1✔
253
            .expect("ArcWeak<T> should have a smart pointer definition");
1✔
254

1✔
255
        // Keep this alive as long as the Arc inside it is used
1✔
256
        let mut arc_storage = MaybeUninit::<Arc<String>>::zeroed();
1✔
257
        let arc_ptr = unsafe {
1✔
258
            let arc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut arc_storage);
1✔
259

1✔
260
            let value = String::from("example");
1✔
261
            let value_ptr = PtrConst::new(&raw const value);
1✔
262

1✔
263
            // SAFETY:
1✔
264
            // - `arc_uninit_ptr` has layout Arc<String>
1✔
265
            // - `value_ptr` is String
1✔
266
            // - `value_ptr` is deallocated
1✔
267
            let returned_ptr = arc_def
1✔
268
                .vtable
1✔
269
                .new_into_fn
1✔
270
                .expect("Arc<T> should have new_into_fn vtable function")(
1✔
271
                arc_uninit_ptr,
1✔
272
                value_ptr,
1✔
273
            );
1✔
274

1✔
275
            // Don't run the destructor
1✔
276
            core::mem::forget(value);
1✔
277

1✔
278
            // Test correctness of the return value of new_into_fn
1✔
279
            // SAFETY: Using correct type Arc<String>
1✔
280
            assert_eq!(
1✔
281
                returned_ptr.as_ptr(),
1✔
282
                arc_uninit_ptr.as_byte_ptr() as *const Arc<String>
1✔
283
            );
284

285
            returned_ptr
1✔
286
        };
1✔
287

1✔
288
        unsafe {
1✔
289
            // SAFETY: `arc_ptr` is valid
1✔
290
            let borrowed = arc_def
1✔
291
                .vtable
1✔
292
                .borrow_fn
1✔
293
                .expect("Arc<T> should have borrow_fn vtable function")(
1✔
294
                arc_ptr.as_const()
1✔
295
            );
1✔
296
            assert_eq!(borrowed.get::<String>(), "example");
1✔
297
        }
298

299
        // Keep this alive as long as the RcWeak inside it is used
300
        let mut new_arc_storage = MaybeUninit::<ArcWeak<String>>::zeroed();
1✔
301
        let weak_ptr = unsafe {
1✔
302
            let weak_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_arc_storage);
1✔
303

1✔
304
            let returned_ptr = arc_def
1✔
305
                .vtable
1✔
306
                .downgrade_into_fn
1✔
307
                .expect("Arc<T> should have downgrade_into_fn vtable function")(
1✔
308
                arc_ptr,
1✔
309
                weak_uninit_ptr,
1✔
310
            );
1✔
311

1✔
312
            // Test correctness of the return value of downgrade_into_fn
1✔
313
            // SAFETY: Using correct type ArcWeak<String>
1✔
314
            assert_eq!(
1✔
315
                returned_ptr.as_ptr(),
1✔
316
                weak_uninit_ptr.as_byte_ptr() as *const ArcWeak<String>
1✔
317
            );
318

319
            returned_ptr
1✔
320
        };
1✔
321

1✔
322
        {
1✔
323
            let mut new_arc_storage = MaybeUninit::<Arc<String>>::zeroed();
1✔
324
            let new_arc_ptr = unsafe {
1✔
325
                let new_arc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_arc_storage);
1✔
326

1✔
327
                // SAFETY: `weak_ptr` is valid and `new_arc_uninit_ptr` has layout Weak<String>
1✔
328
                let returned_ptr = weak_def
1✔
329
                    .vtable
1✔
330
                    .upgrade_into_fn
1✔
331
                    .expect("ArcWeak<T> should have upgrade_into_fn vtable function")(
1✔
332
                    weak_ptr,
1✔
333
                    new_arc_uninit_ptr,
1✔
334
                )
1✔
335
                .expect("Upgrade should be successful");
1✔
336

1✔
337
                // Test correctness of the return value of upgrade_into_fn
1✔
338
                // SAFETY: Using correct type Arc<String>
1✔
339
                assert_eq!(
1✔
340
                    returned_ptr.as_ptr(),
1✔
341
                    new_arc_uninit_ptr.as_byte_ptr() as *const Arc<String>
1✔
342
                );
343

344
                returned_ptr
1✔
345
            };
1✔
346

1✔
347
            unsafe {
1✔
348
                // SAFETY: `new_arc_ptr` is valid
1✔
349
                let borrowed = arc_def
1✔
350
                    .vtable
1✔
351
                    .borrow_fn
1✔
352
                    .expect("Arc<T> should have borrow_fn vtable function")(
1✔
353
                    new_arc_ptr.as_const()
1✔
354
                );
1✔
355
                assert_eq!(borrowed.get::<String>(), "example");
1✔
356
            }
357

358
            unsafe {
1✔
359
                // SAFETY: Proper value at `arc_ptr`, which is not accessed after this
1✔
360
                arc_shape
1✔
361
                    .vtable
1✔
362
                    .drop_in_place
1✔
363
                    .expect("Arc<T> should have drop_in_place vtable function")(
1✔
364
                    new_arc_ptr
1✔
365
                );
1✔
366
            }
1✔
367
        }
1✔
368

1✔
369
        unsafe {
1✔
370
            // SAFETY: Proper value at `arc_ptr`, which is not accessed after this
1✔
371
            arc_shape
1✔
372
                .vtable
1✔
373
                .drop_in_place
1✔
374
                .expect("Arc<T> should have drop_in_place vtable function")(arc_ptr);
1✔
375
        }
1✔
376

1✔
377
        unsafe {
1✔
378
            let mut new_arc_storage = MaybeUninit::<Arc<String>>::zeroed();
1✔
379
            let new_arc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_arc_storage);
1✔
380

1✔
381
            // SAFETY: `weak_ptr` is valid and `new_arc_uninit_ptr` has layout Weak<String>
1✔
382
            if weak_def
1✔
383
                .vtable
1✔
384
                .upgrade_into_fn
1✔
385
                .expect("ArcWeak<T> should have upgrade_into_fn vtable function")(
1✔
386
                weak_ptr,
1✔
387
                new_arc_uninit_ptr,
1✔
388
            )
1✔
389
            .is_some()
1✔
390
            {
NEW
391
                panic!("Upgrade should be unsuccessful")
×
392
            }
1✔
393
        };
1✔
394

1✔
395
        unsafe {
1✔
396
            // SAFETY: Proper value at `weak_ptr`, which is not accessed after this
1✔
397
            weak_shape
1✔
398
                .vtable
1✔
399
                .drop_in_place
1✔
400
                .expect("ArcWeak<T> should have drop_in_place vtable function")(
1✔
401
                weak_ptr
1✔
402
            );
1✔
403
        }
1✔
404
    }
1✔
405

406
    #[test]
407
    fn test_rc_type_params() {
1✔
408
        let [type_param_1] = <Rc<i32>>::SHAPE.type_params else {
1✔
NEW
409
            panic!("Rc<T> should only have 1 type param")
×
410
        };
411
        assert_eq!(type_param_1.shape(), i32::SHAPE);
1✔
412
    }
1✔
413

414
    #[test]
415
    fn test_rc_vtable() {
1✔
416
        facet_testhelpers::setup();
1✔
417

1✔
418
        let rc_shape = <Rc<String>>::SHAPE;
1✔
419
        let rc_def = rc_shape
1✔
420
            .def
1✔
421
            .into_smart_pointer()
1✔
422
            .expect("Rc<T> should have a smart pointer definition");
1✔
423

1✔
424
        let weak_shape = <RcWeak<String>>::SHAPE;
1✔
425
        let weak_def = weak_shape
1✔
426
            .def
1✔
427
            .into_smart_pointer()
1✔
428
            .expect("RcWeak<T> should have a smart pointer definition");
1✔
429

1✔
430
        // Keep this alive as long as the Rc inside it is used
1✔
431
        let mut rc_storage = MaybeUninit::<Rc<String>>::zeroed();
1✔
432
        let rc_ptr = unsafe {
1✔
433
            let rc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut rc_storage);
1✔
434

1✔
435
            let value = String::from("example");
1✔
436
            let value_ptr = PtrConst::new(&raw const value);
1✔
437

1✔
438
            // SAFETY:
1✔
439
            // - `rc_uninit_ptr` has layout Rc<String>
1✔
440
            // - `value_ptr` is String
1✔
441
            // - `value_ptr` is deallocated after this without running the destructor
1✔
442
            let returned_ptr = rc_def
1✔
443
                .vtable
1✔
444
                .new_into_fn
1✔
445
                .expect("Rc<T> should have new_into_fn vtable function")(
1✔
446
                rc_uninit_ptr, value_ptr
1✔
447
            );
1✔
448

1✔
449
            // Don't run the destructor
1✔
450
            core::mem::forget(value);
1✔
451

1✔
452
            // Test correctness of the return value of new_into_fn
1✔
453
            // SAFETY: Using correct type Rc<String>
1✔
454
            assert_eq!(
1✔
455
                returned_ptr.as_ptr(),
1✔
456
                rc_uninit_ptr.as_byte_ptr() as *const Rc<String>
1✔
457
            );
458

459
            returned_ptr
1✔
460
        };
1✔
461

1✔
462
        unsafe {
1✔
463
            // SAFETY: `rc_ptr` is valid
1✔
464
            let borrowed = rc_def
1✔
465
                .vtable
1✔
466
                .borrow_fn
1✔
467
                .expect("Rc<T> should have borrow_fn vtable function")(
1✔
468
                rc_ptr.as_const()
1✔
469
            );
1✔
470
            assert_eq!(borrowed.get::<String>(), "example");
1✔
471
        }
472

473
        // Keep this alive as long as the RcWeak inside it is used
474
        let mut new_rc_storage = MaybeUninit::<RcWeak<String>>::zeroed();
1✔
475
        let weak_ptr = unsafe {
1✔
476
            let weak_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_rc_storage);
1✔
477

1✔
478
            let returned_ptr = rc_def
1✔
479
                .vtable
1✔
480
                .downgrade_into_fn
1✔
481
                .expect("Rc<T> should have downgrade_into_fn vtable function")(
1✔
482
                rc_ptr,
1✔
483
                weak_uninit_ptr,
1✔
484
            );
1✔
485

1✔
486
            // Test correctness of the return value of downgrade_into_fn
1✔
487
            // SAFETY: Using correct type RcWeak<String>
1✔
488
            assert_eq!(
1✔
489
                returned_ptr.as_ptr(),
1✔
490
                weak_uninit_ptr.as_byte_ptr() as *const RcWeak<String>
1✔
491
            );
492

493
            returned_ptr
1✔
494
        };
1✔
495

1✔
496
        {
1✔
497
            let mut new_rc_storage = MaybeUninit::<Rc<String>>::zeroed();
1✔
498
            let new_rc_ptr = unsafe {
1✔
499
                let new_rc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_rc_storage);
1✔
500

1✔
501
                // SAFETY: `weak_ptr` is valid and `new_rc_uninit_ptr` has layout Weak<String>
1✔
502
                let returned_ptr = weak_def
1✔
503
                    .vtable
1✔
504
                    .upgrade_into_fn
1✔
505
                    .expect("RcWeak<T> should have upgrade_into_fn vtable function")(
1✔
506
                    weak_ptr,
1✔
507
                    new_rc_uninit_ptr,
1✔
508
                )
1✔
509
                .expect("Upgrade should be successful");
1✔
510

1✔
511
                // Test correctness of the return value of upgrade_into_fn
1✔
512
                // SAFETY: Using correct type Rc<String>
1✔
513
                assert_eq!(
1✔
514
                    returned_ptr.as_ptr(),
1✔
515
                    new_rc_uninit_ptr.as_byte_ptr() as *const Rc<String>
1✔
516
                );
517

518
                returned_ptr
1✔
519
            };
1✔
520

1✔
521
            unsafe {
1✔
522
                // SAFETY: `new_rc_ptr` is valid
1✔
523
                let borrowed = rc_def
1✔
524
                    .vtable
1✔
525
                    .borrow_fn
1✔
526
                    .expect("Rc<T> should have borrow_fn vtable function")(
1✔
527
                    new_rc_ptr.as_const()
1✔
528
                );
1✔
529
                assert_eq!(borrowed.get::<String>(), "example");
1✔
530
            }
531

532
            unsafe {
1✔
533
                // SAFETY: Proper value at `rc_ptr`, which is not accessed after this
1✔
534
                rc_shape
1✔
535
                    .vtable
1✔
536
                    .drop_in_place
1✔
537
                    .expect("Rc<T> should have drop_in_place vtable function")(
1✔
538
                    new_rc_ptr
1✔
539
                );
1✔
540
            }
1✔
541
        }
1✔
542

1✔
543
        unsafe {
1✔
544
            // SAFETY: Proper value at `rc_ptr`, which is not accessed after this
1✔
545
            rc_shape
1✔
546
                .vtable
1✔
547
                .drop_in_place
1✔
548
                .expect("Rc<T> should have drop_in_place vtable function")(rc_ptr);
1✔
549
        }
1✔
550

1✔
551
        unsafe {
1✔
552
            let mut new_rc_storage = MaybeUninit::<Rc<String>>::zeroed();
1✔
553
            let new_rc_uninit_ptr = PtrUninit::from_maybe_uninit(&mut new_rc_storage);
1✔
554

1✔
555
            // SAFETY: `weak_ptr` is valid and `new_rc_uninit_ptr` has layout Weak<String>
1✔
556
            if weak_def
1✔
557
                .vtable
1✔
558
                .upgrade_into_fn
1✔
559
                .expect("RcWeak<T> should have upgrade_into_fn vtable function")(
1✔
560
                weak_ptr,
1✔
561
                new_rc_uninit_ptr,
1✔
562
            )
1✔
563
            .is_some()
1✔
564
            {
NEW
565
                panic!("Upgrade should be unsuccessful")
×
566
            }
1✔
567
        };
1✔
568

1✔
569
        unsafe {
1✔
570
            // SAFETY: Proper value at `weak_ptr`, which is not accessed after this
1✔
571
            weak_shape
1✔
572
                .vtable
1✔
573
                .drop_in_place
1✔
574
                .expect("RcWeak<T> should have drop_in_place vtable function")(weak_ptr);
1✔
575
        }
1✔
576
    }
1✔
577
}
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