File: bad_counter_ids.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (67 lines) | stat: -rw-r--r-- 1,541 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#![feature(coverage_attribute)]
//@ edition: 2021
//@ compile-flags: -Copt-level=0 -Zmir-opt-level=3

// Regression test for <https://github.com/rust-lang/rust/issues/117012>.
//
// If some coverage counters were removed by MIR optimizations, we need to take
// care not to refer to those counter IDs in coverage mappings, and instead
// replace them with a constant zero value. If we don't, `llvm-cov` might see
// a too-large counter ID and silently discard the entire function from its
// coverage reports.

#[derive(Debug, PartialEq, Eq)]
struct Foo(u32);

fn eq_good() {
    println!("a");
    assert_eq!(Foo(1), Foo(1));
}

fn eq_good_message() {
    println!("b");
    assert_eq!(Foo(1), Foo(1), "message b");
}

fn ne_good() {
    println!("c");
    assert_ne!(Foo(1), Foo(3));
}

fn ne_good_message() {
    println!("d");
    assert_ne!(Foo(1), Foo(3), "message d");
}

fn eq_bad() {
    println!("e");
    assert_eq!(Foo(1), Foo(3));
}

fn eq_bad_message() {
    println!("f");
    assert_eq!(Foo(1), Foo(3), "message f");
}

fn ne_bad() {
    println!("g");
    assert_ne!(Foo(1), Foo(1));
}

fn ne_bad_message() {
    println!("h");
    assert_ne!(Foo(1), Foo(1), "message h");
}

#[coverage(off)]
fn main() {
    eq_good();
    eq_good_message();
    ne_good();
    ne_good_message();

    assert!(std::panic::catch_unwind(eq_bad).is_err());
    assert!(std::panic::catch_unwind(eq_bad_message).is_err());
    assert!(std::panic::catch_unwind(ne_bad).is_err());
    assert!(std::panic::catch_unwind(ne_bad_message).is_err());
}