]> git.proxmox.com Git - rustc.git/blob - tests/coverage/bad_counter_ids.coverage
New upstream version 1.75.0+dfsg1
[rustc.git] / tests / coverage / bad_counter_ids.coverage
1 LL| |#![feature(coverage_attribute)]
2 LL| |// compile-flags: --edition=2021 -Copt-level=0 -Zmir-opt-level=3
3 LL| |
4 LL| |// Regression test for <https://github.com/rust-lang/rust/issues/117012>.
5 LL| |//
6 LL| |// If some coverage counters were removed by MIR optimizations, we need to take
7 LL| |// care not to refer to those counter IDs in coverage mappings, and instead
8 LL| |// replace them with a constant zero value. If we don't, `llvm-cov` might see
9 LL| |// a too-large counter ID and silently discard the entire function from its
10 LL| |// coverage reports.
11 LL| |
12 LL| 8|#[derive(Debug, PartialEq, Eq)]
13 LL| |struct Foo(u32);
14 LL| |
15 LL| 1|fn eq_good() {
16 LL| 1| println!("a");
17 LL| 1| assert_eq!(Foo(1), Foo(1));
18 LL| 1|}
19 LL| |
20 LL| 1|fn eq_good_message() {
21 LL| 1| println!("b");
22 LL| 1| assert_eq!(Foo(1), Foo(1), "message b");
23 ^0
24 LL| 1|}
25 LL| |
26 LL| 1|fn ne_good() {
27 LL| 1| println!("c");
28 LL| 1| assert_ne!(Foo(1), Foo(3));
29 LL| 1|}
30 LL| |
31 LL| 1|fn ne_good_message() {
32 LL| 1| println!("d");
33 LL| 1| assert_ne!(Foo(1), Foo(3), "message d");
34 ^0
35 LL| 1|}
36 LL| |
37 LL| 1|fn eq_bad() {
38 LL| 1| println!("e");
39 LL| 1| assert_eq!(Foo(1), Foo(3));
40 LL| 0|}
41 LL| |
42 LL| 1|fn eq_bad_message() {
43 LL| 1| println!("f");
44 LL| 1| assert_eq!(Foo(1), Foo(3), "message f");
45 LL| 0|}
46 LL| |
47 LL| 1|fn ne_bad() {
48 LL| 1| println!("g");
49 LL| 1| assert_ne!(Foo(1), Foo(1));
50 LL| 0|}
51 LL| |
52 LL| 1|fn ne_bad_message() {
53 LL| 1| println!("h");
54 LL| 1| assert_ne!(Foo(1), Foo(1), "message h");
55 LL| 0|}
56 LL| |
57 LL| |#[coverage(off)]
58 LL| |fn main() {
59 LL| | eq_good();
60 LL| | eq_good_message();
61 LL| | ne_good();
62 LL| | ne_good_message();
63 LL| |
64 LL| | assert!(std::panic::catch_unwind(eq_bad).is_err());
65 LL| | assert!(std::panic::catch_unwind(eq_bad_message).is_err());
66 LL| | assert!(std::panic::catch_unwind(ne_bad).is_err());
67 LL| | assert!(std::panic::catch_unwind(ne_bad_message).is_err());
68 LL| |}
69