]> git.lizzy.rs Git - rust.git/blob - tests/debuginfo/unsized.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / debuginfo / unsized.rs
1 // compile-flags:-g
2
3 // === GDB TESTS ===================================================================================
4
5 // gdb-command:run
6
7 // gdb-command:print a
8 // gdbg-check:$1 = {data_ptr = [...], length = 4}
9 // gdbr-check:$1 = &unsized::Foo<[u8]> {data_ptr: [...], length: 4}
10
11 // gdb-command:print b
12 // gdbg-check:$2 = {data_ptr = [...], length = 4}
13 // gdbr-check:$2 = &unsized::Foo<unsized::Foo<[u8]>> {data_ptr: [...], length: 4}
14
15 // gdb-command:print c
16 // gdbg-check:$3 = {pointer = [...], vtable = [...]}
17 // gdbr-check:$3 = &unsized::Foo<dyn core::fmt::Debug> {pointer: [...], vtable: [...]}
18
19 // gdb-command:print _box
20 // gdbg-check:$4 = {pointer = [...], vtable = [...]}
21 // gdbr-check:$4 = alloc::boxed::Box<unsized::Foo<dyn core::fmt::Debug>, alloc::alloc::Global> {pointer: [...], vtable: [...]}
22
23 // gdb-command:print tuple_slice
24 // gdbg-check:$5 = {data_ptr = [...], length = 2}
25 // gdbr-check:$5 = &(i32, i32, [i32]) {data_ptr: [...], length: 2}
26
27 // gdb-command:print tuple_dyn
28 // gdbg-check:$6 = {pointer = [...], vtable = [...]}
29 // gdbr-check:$6 = &(i32, i32, dyn core::fmt::Debug) {pointer: [...], vtable: [...]}
30
31 // === CDB TESTS ===================================================================================
32
33 // cdb-command: g
34 // cdb-command:dx a
35 // cdb-check:a                [Type: ref$<unsized::Foo<slice2$<u8> > >]
36 // cdb-check:    [+0x000] data_ptr         : 0x[...] [Type: unsized::Foo<slice2$<u8> > *]
37 // cdb-check:    [...] length           : 0x4 [Type: unsigned [...]int[...]
38
39 // cdb-command:dx b
40 // cdb-check:b                [Type: ref$<unsized::Foo<unsized::Foo<slice2$<u8> > > >]
41 // cdb-check:    [+0x000] data_ptr         : 0x[...] [Type: unsized::Foo<unsized::Foo<slice2$<u8> > > *]
42 // cdb-check:    [...] length           : 0x4 [Type: unsigned [...]int[...]
43
44 // cdb-command:dx c
45 // cdb-check:c                [Type: ref$<unsized::Foo<dyn$<core::fmt::Debug> > >]
46 // cdb-check:    [+0x000] pointer          : 0x[...] [Type: unsized::Foo<dyn$<core::fmt::Debug> > *]
47 // cdb-check:    [...] vtable           : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
48
49 // cdb-command:dx _box
50 // cdb-check:
51 // cdb-check:_box             [Type: alloc::boxed::Box<unsized::Foo<dyn$<core::fmt::Debug> >,alloc::alloc::Global>]
52 // cdb-check:[+0x000] pointer          : 0x[...] [Type: unsized::Foo<dyn$<core::fmt::Debug> > *]
53 // cdb-check:[...] vtable           : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
54
55 // cdb-command:dx tuple_slice
56 // cdb-check:tuple_slice      [Type: ref$<tuple$<i32,i32,slice2$<i32> > >]
57 // cdb-check:    [+0x000] data_ptr         : 0x[...] [Type: tuple$<i32,i32,slice2$<i32> > *]
58 // cdb-check:    [...] length           : 0x2 [Type: unsigned [...]int[...]
59
60 // cdb-command:dx tuple_dyn
61 // cdb-check:tuple_dyn        [Type: ref$<tuple$<i32,i32,dyn$<core::fmt::Debug> > >]
62 // cdb-check:    [+0x000] pointer          : 0x[...] [Type: tuple$<i32,i32,dyn$<core::fmt::Debug> > *]
63 // cdb-check:    [...] vtable           : 0x[...] [Type: unsigned [...]int[...] (*)[3]]
64
65 #![feature(unsized_tuple_coercion)]
66 #![feature(omit_gdb_pretty_printer_section)]
67 #![omit_gdb_pretty_printer_section]
68
69 struct Foo<T: ?Sized> {
70     value: T,
71 }
72
73 fn main() {
74     let foo: Foo<Foo<[u8; 4]>> = Foo { value: Foo { value: *b"abc\0" } };
75
76     // We expect `a`, `b`, and `c` to all be fat pointers.
77     // `a` and `b` should be slice-like and thus have a `data_ptr` and `length` field.
78     // `c` should be trait-object-like and thus have a `pointer` and `vtable` field.
79     let a: &Foo<[u8]> = &foo.value;
80     let b: &Foo<Foo<[u8]>> = &foo;
81     let c: &Foo<dyn std::fmt::Debug> = &Foo { value: 7i32 };
82     let _box: Box<Foo<dyn std::fmt::Debug>> = Box::new(Foo { value: 8i32 });
83
84     // Also check unsized tuples
85     let tuple_slice: &(i32, i32, [i32]) = &(0, 1, [2, 3]);
86     let tuple_dyn: &(i32, i32, dyn std::fmt::Debug) = &(0, 1, &3u64);
87
88     zzz(); // #break
89 }
90
91 fn zzz() {
92     ()
93 }