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