]> git.lizzy.rs Git - rust.git/blob - tests/debuginfo/rc_arc.rs
Rollup merge of #107700 - jyn514:tools-builder, r=Mark-Simulacrum
[rust.git] / tests / debuginfo / rc_arc.rs
1 // ignore-windows-gnu: pretty-printers are not loaded
2 // compile-flags:-g
3
4 // min-gdb-version: 8.1
5 // min-cdb-version: 10.0.18317.1001
6
7 // === GDB TESTS ==================================================================================
8
9 // gdb-command:run
10
11 // gdb-command:print rc
12 // gdb-check:[...]$1 = Rc(strong=11, weak=1) = {value = 111, strong = 11, weak = 1}
13 // gdb-command:print arc
14 // gdb-check:[...]$2 = Arc(strong=21, weak=1) = {value = 222, strong = 21, weak = 1}
15
16 // === LLDB TESTS ==================================================================================
17
18 // lldb-command:run
19
20 // lldb-command:print rc
21 // lldb-check:[...]$0 = strong=11, weak=1 { value = 111 }
22 // lldb-command:print arc
23 // lldb-check:[...]$1 = strong=21, weak=1 { data = 222 }
24
25 // === CDB TESTS ==================================================================================
26
27 // cdb-command:g
28
29 // cdb-command:dx rc,d
30 // cdb-check:rc,d             : 111 [Type: alloc::rc::Rc<i32>]
31 // cdb-check:    [Reference count] : 11 [Type: core::cell::Cell<usize>]
32 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
33
34 // cdb-command:dx weak_rc,d
35 // cdb-check:weak_rc,d        : 111 [Type: alloc::rc::Weak<i32>]
36 // cdb-check:    [Reference count] : 11 [Type: core::cell::Cell<usize>]
37 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
38
39 // cdb-command:dx arc,d
40 // cdb-check:arc,d            : 222 [Type: alloc::sync::Arc<i32>]
41 // cdb-check:    [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
42 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
43
44 // cdb-command:dx weak_arc,d
45 // cdb-check:weak_arc,d       : 222 [Type: alloc::sync::Weak<i32>]
46 // cdb-check:    [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
47 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
48
49 // cdb-command:dx dyn_rc,d
50 // cdb-check:dyn_rc,d         [Type: alloc::rc::Rc<dyn$<core::fmt::Debug> >]
51 // cdb-check:    [Reference count] : 31 [Type: core::cell::Cell<usize>]
52 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
53
54 // cdb-command:dx dyn_rc_weak,d
55 // cdb-check:dyn_rc_weak,d    [Type: alloc::rc::Weak<dyn$<core::fmt::Debug> >]
56 // cdb-check:    [Reference count] : 31 [Type: core::cell::Cell<usize>]
57 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
58
59 // cdb-command:dx slice_rc,d
60 // cdb-check:slice_rc,d       : { len=3 } [Type: alloc::rc::Rc<slice2$<u32> >]
61 // cdb-check:    [Length]         : 3 [Type: [...]]
62 // cdb-check:    [Reference count] : 41 [Type: core::cell::Cell<usize>]
63 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
64 // cdb-check:    [0]              : 1 [Type: u32]
65 // cdb-check:    [1]              : 2 [Type: u32]
66 // cdb-check:    [2]              : 3 [Type: u32]
67
68 // cdb-command:dx slice_rc_weak,d
69 // cdb-check:slice_rc_weak,d  : { len=3 } [Type: alloc::rc::Weak<slice2$<u32> >]
70 // cdb-check:    [Length]         : 3 [Type: [...]]
71 // cdb-check:    [Reference count] : 41 [Type: core::cell::Cell<usize>]
72 // cdb-check:    [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
73 // cdb-check:    [0]              : 1 [Type: u32]
74 // cdb-check:    [1]              : 2 [Type: u32]
75 // cdb-check:    [2]              : 3 [Type: u32]
76
77 // cdb-command:dx dyn_arc,d
78 // cdb-check:dyn_arc,d        [Type: alloc::sync::Arc<dyn$<core::fmt::Debug> >]
79 // cdb-check:    [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
80 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
81
82 // cdb-command:dx dyn_arc_weak,d
83 // cdb-check:dyn_arc_weak,d   [Type: alloc::sync::Weak<dyn$<core::fmt::Debug> >]
84 // cdb-check:    [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
85 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
86
87 // cdb-command:dx slice_arc,d
88 // cdb-check:slice_arc,d      : { len=3 } [Type: alloc::sync::Arc<slice2$<u32> >]
89 // cdb-check:    [Length]         : 3 [Type: [...]]
90 // cdb-check:    [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
91 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
92 // cdb-check:    [0]              : 4 [Type: u32]
93 // cdb-check:    [1]              : 5 [Type: u32]
94 // cdb-check:    [2]              : 6 [Type: u32]
95
96 // cdb-command:dx slice_arc_weak,d
97 // cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice2$<u32> >]
98 // cdb-check:    [Length]         : 3 [Type: [...]]
99 // cdb-check:    [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
100 // cdb-check:    [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
101 // cdb-check:    [0]              : 4 [Type: u32]
102 // cdb-check:    [1]              : 5 [Type: u32]
103 // cdb-check:    [2]              : 6 [Type: u32]
104
105 use std::fmt::Debug;
106 use std::rc::Rc;
107 use std::sync::Arc;
108
109 fn main() {
110     let rc = Rc::new(111);
111     inc_ref_count(&rc, 10);
112     let weak_rc = Rc::downgrade(&rc);
113
114     let arc = Arc::new(222);
115     inc_ref_count(&arc, 20);
116     let weak_arc = Arc::downgrade(&arc);
117
118     let dyn_rc: Rc<dyn Debug> = Rc::new(333);
119     inc_ref_count(&dyn_rc, 30);
120     let dyn_rc_weak = Rc::downgrade(&dyn_rc);
121
122     let slice_rc: Rc<[u32]> = Rc::from(vec![1, 2, 3]);
123     inc_ref_count(&slice_rc, 40);
124     let slice_rc_weak = Rc::downgrade(&slice_rc);
125
126     let dyn_arc: Arc<dyn Debug> = Arc::new(444);
127     inc_ref_count(&dyn_arc, 50);
128     let dyn_arc_weak = Arc::downgrade(&dyn_arc);
129
130     let slice_arc: Arc<[u32]> = Arc::from(vec![4, 5, 6]);
131     inc_ref_count(&slice_arc, 60);
132     let slice_arc_weak = Arc::downgrade(&slice_arc);
133
134     zzz(); // #break
135 }
136
137 fn inc_ref_count<T: Clone>(rc: &T, count: usize) {
138     for _ in 0..count {
139         std::mem::forget(rc.clone());
140     }
141 }
142
143 fn zzz() {
144     ()
145 }