]> git.proxmox.com Git - rustc.git/blob - src/test/debuginfo/function-names.rs
Merge branch 'debian/experimental' into debian/sid
[rustc.git] / src / test / debuginfo / function-names.rs
1 // Function names are formatted differently in old versions of GDB
2 // min-gdb-version: 9.2
3
4 // compile-flags:-g
5
6 // === GDB TESTS ===================================================================================
7
8 // Top-level function
9 // gdb-command:info functions -q function_names::main
10 // gdb-check:[...]static fn function_names::main();
11 // gdb-command:info functions -q function_names::generic_func<*
12 // gdb-check:[...]static fn function_names::generic_func(i32) -> i32;
13
14 // Implementations
15 // gdb-command:info functions -q function_names::.*::impl_function.*
16 // gdb-check:[...]static fn function_names::GenericStruct<T1,T2>::impl_function();
17 // gdb-check:[...]static fn function_names::Mod1::TestStruct2::impl_function();
18 // gdb-check:[...]static fn function_names::TestStruct1::impl_function();
19
20 // Trait implementations
21 // gdb-command:info functions -q function_names::.*::trait_function.*
22 // gdb-check:[...]static fn <function_names::GenericStruct<T,i32> as function_names::TestTrait1>::trait_function();
23 // gdb-check:[...]static fn <function_names::GenericStruct<[T; N],f32> as function_names::TestTrait1>::trait_function();
24 // gdb-check:[...]static fn <function_names::Mod1::TestStruct2 as function_names::Mod1::TestTrait2>::trait_function();
25 // gdb-check:[...]static fn <function_names::TestStruct1 as function_names::TestTrait1>::trait_function();
26
27 // Closure
28 // gdb-command:info functions -q function_names::.*::{{closure.*
29 // gdb-check:[...]static fn function_names::GenericStruct<T1,T2>::impl_function::{{closure}}(*mut function_names::{impl#2}::impl_function::{closure#0});
30 // gdb-check:[...]static fn function_names::generic_func::{{closure}}(*mut function_names::generic_func::{closure#0});
31 // gdb-check:[...]static fn function_names::main::{{closure}}(*mut function_names::main::{closure#0});
32
33 // Generator
34 // Generators don't seem to appear in GDB's symbol table.
35
36 // Const generic parameter
37 // gdb-command:info functions -q function_names::const_generic_fn.*
38 // gdb-check:[...]static fn function_names::const_generic_fn_bool();
39 // gdb-check:[...]static fn function_names::const_generic_fn_non_int();
40 // gdb-check:[...]static fn function_names::const_generic_fn_signed_int();
41 // gdb-check:[...]static fn function_names::const_generic_fn_unsigned_int();
42
43 // === CDB TESTS ===================================================================================
44
45 // Top-level function
46 // cdb-command:x a!function_names::main
47 // cdb-check:[...] a!function_names::main (void)
48 // cdb-command:x a!function_names::generic_func<*
49 // cdb-check:[...] a!function_names::generic_func<i32> (int)
50
51 // Implementations
52 // cdb-command:x a!function_names::*::impl_function*
53 // cdb-check:[...] a!function_names::Mod1::TestStruct2::impl_function (void)
54 // cdb-check:[...] a!function_names::TestStruct1::impl_function (void)
55 // cdb-check:[...] a!function_names::GenericStruct<i32,i32>::impl_function<i32,i32> (void)
56
57 // Trait implementations
58 // cdb-command:x a!function_names::*::trait_function*
59 // cdb-check:[...] a!function_names::impl$3::trait_function<i32> (void)
60 // cdb-check:[...] a!function_names::impl$6::trait_function<i32,1> (void)
61 // cdb-check:[...] a!function_names::impl$1::trait_function (void)
62 // cdb-check:[...] a!function_names::impl$5::trait_function3<function_names::TestStruct1> (void)
63 // cdb-check:[...] a!function_names::Mod1::impl$1::trait_function (void)
64
65 // Closure
66 // cdb-command:x a!function_names::*::closure*
67 // cdb-check:[...] a!function_names::impl$2::impl_function::closure$0<i32,i32> (void)
68 // cdb-check:[...] a!function_names::main::closure$0 (void)
69 // cdb-check:[...] a!function_names::generic_func::closure$0<i32> (void)
70
71 // Generator
72 // cdb-command:x a!function_names::*::generator*
73 // cdb-check:[...] a!function_names::main::generator$1 (void)
74
75 // Const generic parameter
76 // cdb-command:x a!function_names::const_generic_fn*
77 // cdb-check:[...] a!function_names::const_generic_fn_bool<false> (void)
78 // cdb-check:[...] a!function_names::const_generic_fn_non_int<CONST$fe3cfa0214ac55c7> (void)
79 // cdb-check:[...] a!function_names::const_generic_fn_unsigned_int<14> (void)
80 // cdb-check:[...] a!function_names::const_generic_fn_signed_int<-7> (void)
81
82 #![allow(unused_variables)]
83 #![feature(omit_gdb_pretty_printer_section)]
84 #![omit_gdb_pretty_printer_section]
85 #![feature(const_generics, generators, generator_trait)]
86 #![allow(incomplete_features)] // for const_generics
87
88 use Mod1::TestTrait2;
89 use std::ops::Generator;
90 use std::pin::Pin;
91
92 fn main() {
93 // Implementations
94 TestStruct1::impl_function();
95 Mod1::TestStruct2::impl_function();
96 GenericStruct::<i32, i32>::impl_function();
97
98 // Trait implementations
99 TestStruct1::trait_function();
100 Mod1::TestStruct2::trait_function();
101 GenericStruct::<i32, i32>::trait_function();
102 GenericStruct::<[i32; 1], f32>::trait_function();
103 GenericStruct::<TestStruct1, usize>::trait_function3();
104
105 // Generic function
106 let _ = generic_func(42);
107
108 // Closure
109 let closure = || { TestStruct1 };
110 closure();
111
112 // Generator
113 let mut generator = || { yield; return; };
114 Pin::new(&mut generator).resume(());
115
116 // Const generic functions
117 const_generic_fn_bool::<false>();
118 const_generic_fn_non_int::<{()}>();
119 const_generic_fn_signed_int::<-7>();
120 const_generic_fn_unsigned_int::<14>();
121 }
122
123 struct TestStruct1;
124 trait TestTrait1 {
125 fn trait_function();
126 }
127
128 // Implementation
129 impl TestStruct1 {
130 pub fn impl_function() {}
131 }
132
133 // Implementation for a trait
134 impl TestTrait1 for TestStruct1 {
135 fn trait_function() {}
136 }
137
138 // Implementation and implementation within a mod
139 mod Mod1 {
140 pub struct TestStruct2;
141 pub trait TestTrait2 {
142 fn trait_function();
143 }
144
145 impl TestStruct2 {
146 pub fn impl_function() {}
147 }
148
149 impl TestTrait2 for TestStruct2 {
150 fn trait_function() {}
151 }
152 }
153
154 struct GenericStruct<T1, T2>(std::marker::PhantomData<(T1, T2)>);
155
156 // Generic implementation
157 impl<T1, T2> GenericStruct<T1, T2> {
158 pub fn impl_function() {
159 // Closure in a generic implementation
160 let closure = || { TestStruct1 };
161 closure();
162 }
163 }
164
165 // Generic trait implementation
166 impl<T> TestTrait1 for GenericStruct<T, i32> {
167 fn trait_function() {}
168 }
169
170 // Implementation based on associated type
171 trait TestTrait3 {
172 type AssocType;
173 fn trait_function3();
174 }
175 impl TestTrait3 for TestStruct1 {
176 type AssocType = usize;
177 fn trait_function3() {}
178 }
179 impl<T: TestTrait3> TestTrait3 for GenericStruct<T, T::AssocType> {
180 type AssocType = T::AssocType;
181 fn trait_function3() {}
182 }
183
184 // Generic trait implementation with const generics
185 impl<T, const N: usize> TestTrait1 for GenericStruct<[T; N], f32> {
186 fn trait_function() {}
187 }
188
189 // Generic function
190 fn generic_func<T>(value: T) -> T {
191 // Closure in a generic function
192 let closure = || { TestStruct1 };
193 closure();
194
195 value
196 }
197
198 fn const_generic_fn_bool<const C: bool>() {}
199 fn const_generic_fn_non_int<const C: ()>() {}
200 fn const_generic_fn_signed_int<const C: i64>() {}
201 fn const_generic_fn_unsigned_int<const C: u32>() {}