]> git.proxmox.com Git - rustc.git/blame - src/test/run-make/coverage-reports/expected_show_coverage.uses_crate.txt
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / run-make / coverage-reports / expected_show_coverage.uses_crate.txt
CommitLineData
fc512014 1 1| |#![allow(unused_assignments, unused_variables)]
cdc7bbd5 2 2| |// compile-flags: -C opt-level=3 # validates coverage now works with optimizations
fc512014
XL
3 3| |use std::fmt::Debug;
4 4| |
5 5| 1|pub fn used_function() {
17df50a5
XL
6 6| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
7 7| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
8 8| 1| // dependent conditions.
fc512014
XL
9 9| 1| let is_true = std::env::args().len() == 1;
10 10| 1| let mut countdown = 0;
11 11| 1| if is_true {
12 12| 1| countdown = 10;
13 13| 1| }
14 ^0
15 14| 1| use_this_lib_crate();
16 15| 1|}
17 16| |
18 17| 2|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
19 18| 2| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
20 19| 2|}
21 ------------------
5099ac24 22 | used_crate::used_only_from_bin_crate_generic_function::<&str>:
fc512014
XL
23 | 17| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
24 | 18| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
25 | 19| 1|}
26 ------------------
5099ac24 27 | used_crate::used_only_from_bin_crate_generic_function::<&alloc::vec::Vec<i32>>:
fc512014
XL
28 | 17| 1|pub fn used_only_from_bin_crate_generic_function<T: Debug>(arg: T) {
29 | 18| 1| println!("used_only_from_bin_crate_generic_function with {:?}", arg);
30 | 19| 1|}
31 ------------------
cdc7bbd5
XL
32 | Unexecuted instantiation: used_crate::used_only_from_bin_crate_generic_function::<_>
33 ------------------
34 20| |// Expect for above function: `Unexecuted instantiation` (see below)
fc512014
XL
35 21| 2|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
36 22| 2| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
37 23| 2|}
38 ------------------
064997fb 39 | used_crate::used_only_from_this_lib_crate_generic_function::<alloc::vec::Vec<i32>>:
fc512014
XL
40 | 21| 1|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
41 | 22| 1| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
42 | 23| 1|}
43 ------------------
064997fb 44 | used_crate::used_only_from_this_lib_crate_generic_function::<&str>:
fc512014
XL
45 | 21| 1|pub fn used_only_from_this_lib_crate_generic_function<T: Debug>(arg: T) {
46 | 22| 1| println!("used_only_from_this_lib_crate_generic_function with {:?}", arg);
47 | 23| 1|}
48 ------------------
49 24| |
50 25| 2|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
51 26| 2| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
52 27| 2|}
53 ------------------
54 | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<alloc::vec::Vec<i32>>:
55 | 25| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
56 | 26| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
57 | 27| 1|}
58 ------------------
59 | used_crate::used_from_bin_crate_and_lib_crate_generic_function::<&str>:
60 | 25| 1|pub fn used_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
61 | 26| 1| println!("used_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
62 | 27| 1|}
63 ------------------
64 28| |
65 29| 2|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
66 30| 2| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
67 31| 2|}
cdc7bbd5
XL
68 ------------------
69 | used_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str>:
70 | 29| 1|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
71 | 30| 1| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
72 | 31| 1|}
73 ------------------
74 | used_crate::used_with_same_type_from_bin_crate_and_lib_crate_generic_function::<&str>:
75 | 29| 1|pub fn used_with_same_type_from_bin_crate_and_lib_crate_generic_function<T: Debug>(arg: T) {
76 | 30| 1| println!("used_with_same_type_from_bin_crate_and_lib_crate_generic_function with {:?}", arg);
77 | 31| 1|}
78 ------------------
fc512014
XL
79 32| |
80 33| 0|pub fn unused_generic_function<T: Debug>(arg: T) {
81 34| 0| println!("unused_generic_function with {:?}", arg);
82 35| 0|}
83 36| |
84 37| 0|pub fn unused_function() {
85 38| 0| let is_true = std::env::args().len() == 1;
86 39| 0| let mut countdown = 2;
87 40| 0| if !is_true {
88 41| 0| countdown = 20;
89 42| 0| }
90 43| 0|}
91 44| |
92 45| 0|fn unused_private_function() {
93 46| 0| let is_true = std::env::args().len() == 1;
94 47| 0| let mut countdown = 2;
95 48| 0| if !is_true {
96 49| 0| countdown = 20;
97 50| 0| }
98 51| 0|}
99 52| |
100 53| 1|fn use_this_lib_crate() {
101 54| 1| used_from_bin_crate_and_lib_crate_generic_function("used from library used_crate.rs");
102 55| 1| used_with_same_type_from_bin_crate_and_lib_crate_generic_function(
103 56| 1| "used from library used_crate.rs",
104 57| 1| );
105 58| 1| let some_vec = vec![5, 6, 7, 8];
106 59| 1| used_only_from_this_lib_crate_generic_function(some_vec);
107 60| 1| used_only_from_this_lib_crate_generic_function("used ONLY from library used_crate.rs");
108 61| 1|}
fc512014 109 62| |
cdc7bbd5
XL
110 63| |// FIXME(#79651): "Unexecuted instantiation" errors appear in coverage results,
111 64| |// for example:
112 65| |//
113 66| |// | Unexecuted instantiation: used_crate::used_only_from_bin_crate_generic_function::<_>
114 67| |//
115 68| |// These notices appear when `llvm-cov` shows instantiations. This may be a
116 69| |// default option, but it can be suppressed with:
117 70| |//
118 71| |// ```shell
119 72| |// $ `llvm-cov show --show-instantiations=0 ...`
120 73| |// ```
fc512014 121 74| |//
cdc7bbd5
XL
122 75| |// The notice is triggered because the function is unused by the library itself,
123 76| |// and when the library is compiled, a synthetic function is generated, so
124 77| |// unused function coverage can be reported. Coverage can be skipped for unused
125 78| |// generic functions with:
fc512014 126 79| |//
cdc7bbd5 127 80| |// ```shell
5099ac24 128 81| |// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...`
cdc7bbd5
XL
129 82| |// ```
130 83| |//
131 84| |// Even though this function is used by `uses_crate.rs` (and
132 85| |// counted), with substitutions for `T`, those instantiations are only generated
133 86| |// when the generic function is actually used (from the binary, not from this
134 87| |// library crate). So the test result shows coverage for all instantiated
135 88| |// versions and their generic type substitutions, plus the `Unexecuted
136 89| |// instantiation` message for the non-substituted version. This is valid, but
137 90| |// unfortunately a little confusing.
138 91| |//
139 92| |// The library crate has its own coverage map, and the only way to show unused
140 93| |// coverage of a generic function is to include the generic function in the
141 94| |// coverage map, marked as an "unused function". If the library were used by
142 95| |// another binary that never used this generic function, then it would be valid
143 96| |// to show the unused generic, with unknown substitution (`_`).
144 97| |//
145 98| |// The alternative is to exclude all generics from being included in the "unused
146 99| |// functions" list, which would then omit coverage results for
147 100| |// `unused_generic_function<T>()`, below.
fc512014 148