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

facet-rs / facet / 14551208373

19 Apr 2025 05:09PM UTC coverage: 45.913% (+1.6%) from 44.272%
14551208373

Pull #307

github

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

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

279 existing lines in 3 files 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 core::mem::MaybeUninit;
225

226
    use super::*;
227

228
    use crate::PtrUninit;
229

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

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

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

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

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

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

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

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

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

284
            returned_ptr
1✔
285
        };
1✔
286

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

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

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

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

318
            returned_ptr
1✔
319
        };
1✔
320

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

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

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

343
                returned_ptr
1✔
344
            };
1✔
345

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

458
            returned_ptr
1✔
459
        };
1✔
460

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

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

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

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

492
            returned_ptr
1✔
493
        };
1✔
494

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

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

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

517
                returned_ptr
1✔
518
            };
1✔
519

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

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

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

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

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

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