]> git.proxmox.com Git - rustc.git/blame - tests/run-coverage/closure.coverage
New upstream version 1.74.1+dfsg1
[rustc.git] / tests / run-coverage / closure.coverage
CommitLineData
add651ee
FG
1 LL| |#![allow(unused_assignments, unused_variables)]
2 LL| |// compile-flags: -C opt-level=2
781aab86
FG
3 LL| |
4 LL| |// This test used to be sensitive to certain coverage-specific hacks in
5 LL| |// `rustc_middle/mir/mono.rs`, but those hacks were later cleaned up by
6 LL| |// <https://github.com/rust-lang/rust/pull/83666>.
7 LL| |
8 LL| 1|fn main() {
add651ee
FG
9 LL| 1| // Initialize test constants in a way that cannot be determined at compile time, to ensure
10 LL| 1| // rustc and LLVM cannot optimize out statements (or coverage counters) downstream from
11 LL| 1| // dependent conditions.
12 LL| 1| let is_true = std::env::args().len() == 1;
781aab86 13 LL| 1| let is_false = !is_true;
add651ee
FG
14 LL| 1|
15 LL| 1| let mut some_string = Some(String::from("the string content"));
16 LL| 1| println!(
17 LL| 1| "The string or alt: {}"
18 LL| 1| ,
19 LL| 1| some_string
20 LL| 1| .
21 LL| 1| unwrap_or_else
22 LL| 1| (
23 LL| 1| ||
24 LL| 0| {
25 LL| 0| let mut countdown = 0;
26 LL| 0| if is_false {
27 LL| 0| countdown = 10;
28 LL| 0| }
29 LL| 0| "alt string 1".to_owned()
30 LL| 1| }
31 LL| 1| )
32 LL| 1| );
33 LL| 1|
34 LL| 1| some_string = Some(String::from("the string content"));
35 LL| 1| let
36 LL| 1| a
37 LL| | =
38 LL| | ||
39 LL| 0| {
40 LL| 0| let mut countdown = 0;
41 LL| 0| if is_false {
42 LL| 0| countdown = 10;
43 LL| 0| }
44 LL| 0| "alt string 2".to_owned()
45 LL| 0| };
46 LL| 1| println!(
47 LL| 1| "The string or alt: {}"
48 LL| 1| ,
49 LL| 1| some_string
50 LL| 1| .
51 LL| 1| unwrap_or_else
52 LL| 1| (
53 LL| 1| a
54 LL| 1| )
55 LL| 1| );
56 LL| 1|
57 LL| 1| some_string = None;
58 LL| 1| println!(
59 LL| 1| "The string or alt: {}"
60 LL| 1| ,
61 LL| 1| some_string
62 LL| 1| .
63 LL| 1| unwrap_or_else
64 LL| 1| (
65 LL| 1| ||
66 LL| 1| {
67 LL| 1| let mut countdown = 0;
68 LL| 1| if is_false {
69 LL| 0| countdown = 10;
70 LL| 1| }
71 LL| 1| "alt string 3".to_owned()
72 LL| 1| }
73 LL| 1| )
74 LL| 1| );
75 LL| 1|
76 LL| 1| some_string = None;
77 LL| 1| let
78 LL| 1| a
781aab86
FG
79 LL| | =
80 LL| | ||
add651ee
FG
81 LL| 1| {
82 LL| 1| let mut countdown = 0;
83 LL| 1| if is_false {
84 LL| 0| countdown = 10;
85 LL| 1| }
86 LL| 1| "alt string 4".to_owned()
87 LL| 1| };
88 LL| 1| println!(
89 LL| 1| "The string or alt: {}"
90 LL| 1| ,
91 LL| 1| some_string
92 LL| 1| .
93 LL| 1| unwrap_or_else
94 LL| 1| (
95 LL| 1| a
96 LL| 1| )
97 LL| 1| );
98 LL| 1|
99 LL| 1| let
100 LL| 1| quote_closure
781aab86
FG
101 LL| | =
102 LL| | |val|
add651ee
FG
103 LL| 5| {
104 LL| 5| let mut countdown = 0;
105 LL| 5| if is_false {
106 LL| 0| countdown = 10;
107 LL| 5| }
108 LL| 5| format!("'{}'", val)
109 LL| 5| };
110 LL| 1| println!(
111 LL| 1| "Repeated, quoted string: {:?}"
112 LL| 1| ,
113 LL| 1| std::iter::repeat("repeat me")
114 LL| 1| .take(5)
115 LL| 1| .map
116 LL| 1| (
117 LL| 1| quote_closure
118 LL| 1| )
119 LL| 1| .collect::<Vec<_>>()
120 LL| 1| );
121 LL| 1|
122 LL| 1| let
123 LL| 1| _unused_closure
124 LL| | =
125 LL| | |
126 LL| | mut countdown
127 LL| | |
128 LL| 0| {
129 LL| 0| if is_false {
130 LL| 0| countdown = 10;
131 LL| 0| }
132 LL| 0| "closure should be unused".to_owned()
133 LL| 0| };
134 LL| |
135 LL| 1| let mut countdown = 10;
136 LL| 1| let _short_unused_closure = | _unused_arg: u8 | countdown += 1;
fc512014 137 ^0
add651ee
FG
138 LL| |
139 LL| |
140 LL| 1| let short_used_covered_closure_macro = | used_arg: u8 | println!("called");
141 LL| 1| let short_used_not_covered_closure_macro = | used_arg: u8 | println!("not called");
17df50a5 142 ^0
add651ee 143 LL| 1| let _short_unused_closure_macro = | _unused_arg: u8 | println!("not called");
17df50a5 144 ^0
add651ee
FG
145 LL| |
146 LL| |
147 LL| |
148 LL| |
149 LL| 1| let _short_unused_closure_block = | _unused_arg: u8 | { println!("not called") };
fc512014 150 ^0
add651ee
FG
151 LL| |
152 LL| 1| let _shortish_unused_closure = | _unused_arg: u8 | {
153 LL| 0| println!("not called")
154 LL| 0| };
155 LL| |
156 LL| 1| let _as_short_unused_closure = |
157 LL| | _unused_arg: u8
158 LL| 0| | { println!("not called") };
159 LL| |
160 LL| 1| let _almost_as_short_unused_closure = |
161 LL| | _unused_arg: u8
162 LL| 0| | { println!("not called") }
163 LL| | ;
164 LL| |
165 LL| |
166 LL| |
167 LL| |
168 LL| |
169 LL| 1| let _short_unused_closure_line_break_no_block = | _unused_arg: u8 |
170 LL| 0|println!("not called")
171 LL| | ;
172 LL| |
173 LL| 1| let _short_unused_closure_line_break_no_block2 =
174 LL| | | _unused_arg: u8 |
175 LL| 0| println!(
176 LL| 0| "not called"
177 LL| 0| )
178 LL| | ;
179 LL| |
180 LL| 1| let short_used_not_covered_closure_line_break_no_block_embedded_branch =
181 LL| | | _unused_arg: u8 |
182 LL| 0| println!(
183 LL| 0| "not called: {}",
184 LL| 0| if is_true { "check" } else { "me" }
185 LL| 0| )
186 LL| | ;
187 LL| |
188 LL| 1| let short_used_not_covered_closure_line_break_block_embedded_branch =
781aab86 189 LL| | | _unused_arg: u8 |
add651ee
FG
190 LL| 0| {
191 LL| 0| println!(
192 LL| 0| "not called: {}",
193 LL| 0| if is_true { "check" } else { "me" }
194 LL| | )
195 LL| 0| }
196 LL| | ;
197 LL| |
198 LL| 1| let short_used_covered_closure_line_break_no_block_embedded_branch =
781aab86 199 LL| | | _unused_arg: u8 |
add651ee
FG
200 LL| 1| println!(
201 LL| 1| "not called: {}",
202 LL| 1| if is_true { "check" } else { "me" }
17df50a5 203 ^0
add651ee
FG
204 LL| 1| )
205 LL| | ;
206 LL| |
207 LL| 1| let short_used_covered_closure_line_break_block_embedded_branch =
781aab86 208 LL| | | _unused_arg: u8 |
add651ee
FG
209 LL| 1| {
210 LL| 1| println!(
211 LL| 1| "not called: {}",
212 LL| 1| if is_true { "check" } else { "me" }
17df50a5 213 ^0
add651ee
FG
214 LL| | )
215 LL| 1| }
216 LL| | ;
217 LL| |
218 LL| 1| if is_false {
219 LL| 0| short_used_not_covered_closure_macro(0);
220 LL| 0| short_used_not_covered_closure_line_break_no_block_embedded_branch(0);
221 LL| 0| short_used_not_covered_closure_line_break_block_embedded_branch(0);
222 LL| 1| }
223 LL| 1| short_used_covered_closure_macro(0);
224 LL| 1| short_used_covered_closure_line_break_no_block_embedded_branch(0);
225 LL| 1| short_used_covered_closure_line_break_block_embedded_branch(0);
226 LL| 1|}
29967ef6 227