Skip to content

Commit

Permalink
Add test for coverage on a body-less trait function
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss authored and Zalathar committed Dec 23, 2024
1 parent 0efa90f commit 5d9f17f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
9 changes: 9 additions & 0 deletions tests/ui/coverage-attr/no-coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ trait Trait {
type T;

type U;

#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
fn f(&self);

#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
fn g();
}

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

#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
type U = impl Trait; //~ ERROR unconstrained opaque type

fn f(&self) {}
fn g() {}
}

extern "C" {
Expand Down
36 changes: 26 additions & 10 deletions tests/ui/coverage-attr/no-coverage.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ LL | / trait Trait {
LL | | #[coverage(off)]
LL | | const X: u32;
... |
LL | | type U;
LL | | fn g();
LL | | }
| |_- not a function or closure

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

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

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

error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:24:5
--> $DIR/no-coverage.rs:19:5
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
LL | fn f(&self);
| ------------ not a function or closure

error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:22:5
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
LL | fn g();
| ------- not a function or closure

error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:30:5
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
LL | type T = Self;
| -------------- not a function or closure

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

error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:32:5
--> $DIR/no-coverage.rs:41:5
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
LL | static X: u32;
| -------------- not a function or closure

error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:35:5
--> $DIR/no-coverage.rs:44:5
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
LL | type T;
| ------- not a function or closure

error: unconstrained opaque type
--> $DIR/no-coverage.rs:28:14
--> $DIR/no-coverage.rs:34:14
|
LL | type U = impl Trait;
| ^^^^^^^^^^
|
= note: `U` must be used in combination with a concrete type within the same impl

error: aborting due to 11 previous errors
error: aborting due to 13 previous errors

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

0 comments on commit 5d9f17f

Please sign in to comment.