]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/debug-vtable.rs
Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726
[rust.git] / src / test / codegen / debug-vtable.rs
1 // compile-flags: -Cdebuginfo=2 -Copt-level=0 -Ccodegen-units=1
2 // ignore-tidy-linelength
3
4 // This test checks the debuginfo for the expected 3 vtables is generated for correct names and number
5 // of entries.
6
7 // NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTrait>::{vtable}"
8 // MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTrait>::vtable$"
9 // NONMSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()",
10 // MSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_const$<tuple$<> >",
11 // CHECK: !DISubrange(count: 5
12
13 // NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTraitWithGenerics<u64, i8>>::{vtable}"
14 // MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTraitWithGenerics<u64,i8> >::vtable$"
15 // CHECK: !DISubrange(count: 4
16
17 // NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::Foo as _>::{vtable}"
18 // MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, _>::vtable$"
19 // CHECK: !DISubrange(count: 3
20
21 // NONMSVC-LABEL: !DIGlobalVariable(name: "<debug_vtable::bar::{closure#0} as core::ops::function::FnOnce<(core::option::Option<&dyn core::ops::function::Fn<(), Output=()>>)>>::{vtable}"
22 // MSVC-LABEL: !DIGlobalVariable(name: "impl$<debug_vtable::bar::closure$0, core::ops::function::FnOnce<tuple$<enum$<core::option::Option<ref$<dyn$<core::ops::function::Fn<tuple$<>,assoc$<Output,tuple$<> > > > > >, {{.*}}, {{.*}}, Some> > > >::vtable$"
23
24 #![crate_type = "lib"]
25
26 pub struct Foo;
27
28 pub trait SomeTrait {
29     fn method1(&self) -> u32;
30     fn method2(&self) -> u32;
31 }
32
33 impl SomeTrait for Foo {
34     fn method1(&self) -> u32 { 1 }
35     fn method2(&self) -> u32 { 2 }
36 }
37
38 pub trait SomeTraitWithGenerics<T, U> {
39     fn method1(&self) -> (T, U);
40 }
41
42 impl SomeTraitWithGenerics<u64, i8> for Foo {
43     fn method1(&self) -> (u64, i8) { (1, 2) }
44 }
45
46 pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) {
47     let y: &dyn SomeTrait = x;
48     let z: &dyn SomeTraitWithGenerics<u64, i8> = x;
49     (y.method1(), z.method1(), x as &dyn Send)
50 }
51
52 // Constructing the debuginfo name for the FnOnce vtable below initially caused an ICE on MSVC
53 // because the trait type contains a late bound region that needed to be erased before the type
54 // layout for the niche enum `Option<&dyn Fn()>` could be computed.
55 pub fn bar() -> Box<dyn FnOnce(Option<&dyn Fn()>)> {
56     Box::new(|_x: Option<&dyn Fn()>| {})
57 }