]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/debug-vtable.rs
Auto merge of #93626 - wesleywiser:fix_hashmap_natvis, r=michaelwoerister
[rust.git] / src / test / codegen / debug-vtable.rs
1 // This test checks the debuginfo for the expected 3 vtables is generated for correct names and number
2 // of entries.
3
4 // Use the v0 symbol mangling scheme to codegen order independent of rustc version.
5 // Unnamed items like shims are generated in lexicographical order of their symbol name and in the
6 // legacy mangling scheme rustc version and generic parameters are both hashed into a single part
7 // of the name, thus randomizing item order with respect to rustc version.
8
9 // compile-flags: -Cdebuginfo=2 -Copt-level=0 -Csymbol-mangling-version=v0
10 // ignore-tidy-linelength
11
12 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTrait>::{vtable}"
13 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTrait>::vtable$"
14 // NONMSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const ()",
15 // MSVC: !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_const$<tuple$<> >",
16 // CHECK: !DISubrange(count: 5
17
18 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as debug_vtable::SomeTraitWithGenerics<u64, i8>>::{vtable}"
19 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, debug_vtable::SomeTraitWithGenerics<u64,i8> >::vtable$"
20 // CHECK: !DISubrange(count: 4
21
22 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::Foo as _>::{vtable}"
23 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::Foo, _>::vtable$"
24 // CHECK: !DISubrange(count: 3
25
26 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::bar::{closure_env#0} as core::ops::function::FnOnce<(core::option::Option<&dyn core::ops::function::Fn<(), Output=()>>)>>::{vtable}"
27 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::bar::closure_env$0, core::ops::function::FnOnce<tuple$<enum$<core::option::Option<ref$<dyn$<core::ops::function::Fn<tuple$<>,assoc$<Output,tuple$<> > > > > >, {{.*}}, {{.*}}, Some> > > >::vtable$"
28
29 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::generic_closure::{closure_env#0}<bool> as core::ops::function::FnOnce<()>>::{vtable}"
30 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::generic_closure::closure_env$0<bool>, core::ops::function::FnOnce<tuple$<> > >::vtable$
31
32 // NONMSVC: !DIGlobalVariable(name: "<debug_vtable::generic_closure::{closure_env#0}<u32> as core::ops::function::FnOnce<()>>::{vtable}"
33 // MSVC: !DIGlobalVariable(name: "impl$<debug_vtable::generic_closure::closure_env$0<u32>, core::ops::function::FnOnce<tuple$<> > >::vtable$
34
35 #![crate_type = "lib"]
36
37 pub struct Foo;
38
39 pub trait SomeTrait {
40     fn method1(&self) -> u32;
41     fn method2(&self) -> u32;
42 }
43
44 impl SomeTrait for Foo {
45     fn method1(&self) -> u32 {
46         1
47     }
48     fn method2(&self) -> u32 {
49         2
50     }
51 }
52
53 pub trait SomeTraitWithGenerics<T, U> {
54     fn method1(&self) -> (T, U);
55 }
56
57 impl SomeTraitWithGenerics<u64, i8> for Foo {
58     fn method1(&self) -> (u64, i8) {
59         (1, 2)
60     }
61 }
62
63 pub fn foo(x: &Foo) -> (u32, (u64, i8), &dyn Send) {
64     let y: &dyn SomeTrait = x;
65     let z: &dyn SomeTraitWithGenerics<u64, i8> = x;
66     (y.method1(), z.method1(), x as &dyn Send)
67 }
68
69 // Constructing the debuginfo name for the FnOnce vtable below initially caused an ICE on MSVC
70 // because the trait type contains a late bound region that needed to be erased before the type
71 // layout for the niche enum `Option<&dyn Fn()>` could be computed.
72 pub fn bar() -> Box<dyn FnOnce(Option<&dyn Fn()>)> {
73     Box::new(|_x: Option<&dyn Fn()>| {})
74 }
75
76 fn generic_closure<T: 'static>(x: T) -> Box<dyn FnOnce() -> T> {
77     Box::new(move || x)
78 }
79
80 pub fn instantiate_generic_closures() -> (Box<dyn FnOnce() -> u32>, Box<dyn FnOnce() -> bool>) {
81     (generic_closure(1u32), generic_closure(false))
82 }