Skip to content

Commit 369be18

Browse files
authored
Rollup merge of #134517 - ehuss:coverage-trait-test, r=Zalathar
Add tests for coverage attribute on trait functions This adds tests for the coverage attribute on trait functions. cc #84605 (comment)
2 parents 95c33e3 + 5d9f17f commit 369be18

File tree

5 files changed

+95
-10
lines changed

5 files changed

+95
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Function name: <trait_impl_inherit::S as trait_impl_inherit::T>::f
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 05, 02, 06]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 17, 5) to (start + 2, 6)
8+
Highest counter ID seen: c0
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// Checks that `#[coverage(..)]` in a trait method is not inherited in an
3+
LL| |// implementation.
4+
LL| |//@ edition: 2021
5+
LL| |//@ reference: attributes.coverage.trait-impl-inherit
6+
LL| |
7+
LL| |trait T {
8+
LL| | #[coverage(off)]
9+
LL| | fn f(&self) {
10+
LL| | println!("default");
11+
LL| | }
12+
LL| |}
13+
LL| |
14+
LL| |struct S;
15+
LL| |
16+
LL| |impl T for S {
17+
LL| 1| fn f(&self) {
18+
LL| 1| println!("impl S");
19+
LL| 1| }
20+
LL| |}
21+
LL| |
22+
LL| |#[coverage(off)]
23+
LL| |fn main() {
24+
LL| | S.f();
25+
LL| |}
26+
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(coverage_attribute)]
2+
// Checks that `#[coverage(..)]` in a trait method is not inherited in an
3+
// implementation.
4+
//@ edition: 2021
5+
//@ reference: attributes.coverage.trait-impl-inherit
6+
7+
trait T {
8+
#[coverage(off)]
9+
fn f(&self) {
10+
println!("default");
11+
}
12+
}
13+
14+
struct S;
15+
16+
impl T for S {
17+
fn f(&self) {
18+
println!("impl S");
19+
}
20+
}
21+
22+
#[coverage(off)]
23+
fn main() {
24+
S.f();
25+
}

tests/ui/coverage-attr/no-coverage.rs

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ trait Trait {
1515
type T;
1616

1717
type U;
18+
19+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
20+
fn f(&self);
21+
22+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
23+
fn g();
1824
}
1925

2026
#[coverage(off)]
@@ -26,6 +32,9 @@ impl Trait for () {
2632

2733
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
2834
type U = impl Trait; //~ ERROR unconstrained opaque type
35+
36+
fn f(&self) {}
37+
fn g() {}
2938
}
3039

3140
extern "C" {

tests/ui/coverage-attr/no-coverage.stderr

+26-10
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ LL | / trait Trait {
77
LL | | #[coverage(off)]
88
LL | | const X: u32;
99
... |
10-
LL | | type U;
10+
LL | | fn g();
1111
LL | | }
1212
| |_- not a function or closure
1313

1414
error[E0788]: attribute should be applied to a function definition or closure
15-
--> $DIR/no-coverage.rs:41:5
15+
--> $DIR/no-coverage.rs:50:5
1616
|
1717
LL | #[coverage(off)]
1818
| ^^^^^^^^^^^^^^^^
1919
LL | let _ = ();
2020
| ----------- not a function or closure
2121

2222
error[E0788]: attribute should be applied to a function definition or closure
23-
--> $DIR/no-coverage.rs:45:9
23+
--> $DIR/no-coverage.rs:54:9
2424
|
2525
LL | #[coverage(off)]
2626
| ^^^^^^^^^^^^^^^^
2727
LL | () => (),
2828
| -------- not a function or closure
2929

3030
error[E0788]: attribute should be applied to a function definition or closure
31-
--> $DIR/no-coverage.rs:49:5
31+
--> $DIR/no-coverage.rs:58:5
3232
|
3333
LL | #[coverage(off)]
3434
| ^^^^^^^^^^^^^^^^
@@ -52,45 +52,61 @@ LL | type T;
5252
| ------- not a function or closure
5353

5454
error[E0788]: attribute should be applied to a function definition or closure
55-
--> $DIR/no-coverage.rs:24:5
55+
--> $DIR/no-coverage.rs:19:5
56+
|
57+
LL | #[coverage(off)]
58+
| ^^^^^^^^^^^^^^^^
59+
LL | fn f(&self);
60+
| ------------ not a function or closure
61+
62+
error[E0788]: attribute should be applied to a function definition or closure
63+
--> $DIR/no-coverage.rs:22:5
64+
|
65+
LL | #[coverage(off)]
66+
| ^^^^^^^^^^^^^^^^
67+
LL | fn g();
68+
| ------- not a function or closure
69+
70+
error[E0788]: attribute should be applied to a function definition or closure
71+
--> $DIR/no-coverage.rs:30:5
5672
|
5773
LL | #[coverage(off)]
5874
| ^^^^^^^^^^^^^^^^
5975
LL | type T = Self;
6076
| -------------- not a function or closure
6177

6278
error[E0788]: attribute should be applied to a function definition or closure
63-
--> $DIR/no-coverage.rs:27:5
79+
--> $DIR/no-coverage.rs:33:5
6480
|
6581
LL | #[coverage(off)]
6682
| ^^^^^^^^^^^^^^^^
6783
LL | type U = impl Trait;
6884
| -------------------- not a function or closure
6985

7086
error[E0788]: attribute should be applied to a function definition or closure
71-
--> $DIR/no-coverage.rs:32:5
87+
--> $DIR/no-coverage.rs:41:5
7288
|
7389
LL | #[coverage(off)]
7490
| ^^^^^^^^^^^^^^^^
7591
LL | static X: u32;
7692
| -------------- not a function or closure
7793

7894
error[E0788]: attribute should be applied to a function definition or closure
79-
--> $DIR/no-coverage.rs:35:5
95+
--> $DIR/no-coverage.rs:44:5
8096
|
8197
LL | #[coverage(off)]
8298
| ^^^^^^^^^^^^^^^^
8399
LL | type T;
84100
| ------- not a function or closure
85101

86102
error: unconstrained opaque type
87-
--> $DIR/no-coverage.rs:28:14
103+
--> $DIR/no-coverage.rs:34:14
88104
|
89105
LL | type U = impl Trait;
90106
| ^^^^^^^^^^
91107
|
92108
= note: `U` must be used in combination with a concrete type within the same impl
93109

94-
error: aborting due to 11 previous errors
110+
error: aborting due to 13 previous errors
95111

96112
For more information about this error, try `rustc --explain E0788`.

0 commit comments

Comments
 (0)