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