Skip to content

Commit af4631a

Browse files
committed
Add a test for -Zprint-vtable-sizes
1 parent dc0fba0 commit af4631a

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// check-pass
2+
// compile-flags: -Z print-vtable-sizes
3+
#![crate_type = "lib"]
4+
5+
trait A<T: help::V>: AsRef<[T::V]> + AsMut<[T::V]> {}
6+
7+
trait B<T>: AsRef<T> + AsRef<T> + AsRef<T> + AsRef<T> {}
8+
9+
trait C {
10+
fn x() {} // not object safe, shouldn't be reported
11+
}
12+
13+
// This ideally should not have any upcasting cost,
14+
// but currently does due to a bug
15+
trait D: Send + Sync + help::MarkerWithSuper {}
16+
17+
// This can't have no cost without reordering,
18+
// because `Super::f`.
19+
trait E: help::MarkerWithSuper + Send + Sync {}
20+
21+
trait F {
22+
fn a(&self);
23+
fn b(&self);
24+
fn c(&self);
25+
26+
fn d() -> Self
27+
where
28+
Self: Sized;
29+
}
30+
31+
trait G: AsRef<u8> + AsRef<u16> + help::MarkerWithSuper {
32+
fn a(&self);
33+
fn b(&self);
34+
fn c(&self);
35+
fn d(&self);
36+
fn e(&self);
37+
38+
fn f() -> Self
39+
where
40+
Self: Sized;
41+
}
42+
43+
// Traits with the same name
44+
const _: () = {
45+
trait S {}
46+
};
47+
const _: () = {
48+
trait S {}
49+
};
50+
51+
mod help {
52+
pub trait V {
53+
type V;
54+
}
55+
56+
pub trait MarkerWithSuper: Super {}
57+
58+
pub trait Super {
59+
fn f(&self);
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "D", "entries": "7", "entries_ignoring_upcasting": "4", "entries_for_upcasting": "3", "upcasting_cost_percent": "75" }
2+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "E", "entries": "6", "entries_ignoring_upcasting": "4", "entries_for_upcasting": "2", "upcasting_cost_percent": "50" }
3+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "G", "entries": "14", "entries_ignoring_upcasting": "11", "entries_for_upcasting": "3", "upcasting_cost_percent": "27.27272727272727" }
4+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "A", "entries": "6", "entries_ignoring_upcasting": "5", "entries_for_upcasting": "1", "upcasting_cost_percent": "20" }
5+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "B", "entries": "4", "entries_ignoring_upcasting": "4", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
6+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "F", "entries": "6", "entries_ignoring_upcasting": "6", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
7+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "_::S", "entries": "3", "entries_ignoring_upcasting": "3", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
8+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "_::S", "entries": "3", "entries_ignoring_upcasting": "3", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
9+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "help::MarkerWithSuper", "entries": "4", "entries_ignoring_upcasting": "4", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
10+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "help::Super", "entries": "4", "entries_ignoring_upcasting": "4", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }
11+
print-vtable-sizes { "crate_name": "<UNKNOWN_CRATE>", "trait_name": "help::V", "entries": "3", "entries_ignoring_upcasting": "3", "entries_for_upcasting": "0", "upcasting_cost_percent": "0" }

0 commit comments

Comments
 (0)