From 64f14b2019245d707769166dd3d06c067d71738b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 19 Dec 2024 06:51:07 -0800 Subject: [PATCH] Add test for coverage on a body-less trait function --- .../coverage/attr/trait-impl-inherit.cov-map | 4 +-- .../coverage/attr/trait-impl-inherit.coverage | 1 + tests/coverage/attr/trait-impl-inherit.rs | 1 + tests/ui/coverage-attr/no-coverage.rs | 9 +++++ tests/ui/coverage-attr/no-coverage.stderr | 36 +++++++++++++------ 5 files changed, 39 insertions(+), 12 deletions(-) diff --git a/tests/coverage/attr/trait-impl-inherit.cov-map b/tests/coverage/attr/trait-impl-inherit.cov-map index b50aa6740462b..d1d4fdb96a672 100644 --- a/tests/coverage/attr/trait-impl-inherit.cov-map +++ b/tests/coverage/attr/trait-impl-inherit.cov-map @@ -1,9 +1,9 @@ Function name: ::f -Raw bytes (9): 0x[01, 01, 00, 01, 01, 0f, 05, 02, 06] +Raw bytes (9): 0x[01, 01, 00, 01, 01, 10, 05, 02, 06] Number of files: 1 - file 0 => global file 1 Number of expressions: 0 Number of file 0 mappings: 1 -- Code(Counter(0)) at (prev + 15, 5) to (start + 2, 6) +- Code(Counter(0)) at (prev + 16, 5) to (start + 2, 6) Highest counter ID seen: c0 diff --git a/tests/coverage/attr/trait-impl-inherit.coverage b/tests/coverage/attr/trait-impl-inherit.coverage index 90a9d325c21d8..f056f579b9c5e 100644 --- a/tests/coverage/attr/trait-impl-inherit.coverage +++ b/tests/coverage/attr/trait-impl-inherit.coverage @@ -1,5 +1,6 @@ LL| |// Checks that `#[coverage(..)]` in a trait method is not inherited in an LL| |// implementation. + LL| |//@ edition: 2021 LL| |//@ reference: attributes.coverage.trait-impl-inherit LL| | LL| |trait T { diff --git a/tests/coverage/attr/trait-impl-inherit.rs b/tests/coverage/attr/trait-impl-inherit.rs index 80fbed1881e86..480d4c5168d99 100644 --- a/tests/coverage/attr/trait-impl-inherit.rs +++ b/tests/coverage/attr/trait-impl-inherit.rs @@ -1,5 +1,6 @@ // Checks that `#[coverage(..)]` in a trait method is not inherited in an // implementation. +//@ edition: 2021 //@ reference: attributes.coverage.trait-impl-inherit trait T { diff --git a/tests/ui/coverage-attr/no-coverage.rs b/tests/ui/coverage-attr/no-coverage.rs index 691456aee40ee..81fbc288faece 100644 --- a/tests/ui/coverage-attr/no-coverage.rs +++ b/tests/ui/coverage-attr/no-coverage.rs @@ -14,6 +14,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)] @@ -25,6 +31,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" { diff --git a/tests/ui/coverage-attr/no-coverage.stderr b/tests/ui/coverage-attr/no-coverage.stderr index 2421d2771f585..0d30230439dc4 100644 --- a/tests/ui/coverage-attr/no-coverage.stderr +++ b/tests/ui/coverage-attr/no-coverage.stderr @@ -7,12 +7,12 @@ 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:40:5 + --> $DIR/no-coverage.rs:49:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | let _ = (); | ----------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:44:9 + --> $DIR/no-coverage.rs:53:9 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | () => (), | -------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:48:5 + --> $DIR/no-coverage.rs:57:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -52,7 +52,23 @@ LL | type T; | ------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:23:5 + --> $DIR/no-coverage.rs:18: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:21: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:29:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -60,7 +76,7 @@ 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:26:5 + --> $DIR/no-coverage.rs:32:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -68,7 +84,7 @@ 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:31:5 + --> $DIR/no-coverage.rs:40:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -76,7 +92,7 @@ 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:34:5 + --> $DIR/no-coverage.rs:43:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -84,13 +100,13 @@ LL | type T; | ------- not a function or closure error: unconstrained opaque type - --> $DIR/no-coverage.rs:27:14 + --> $DIR/no-coverage.rs:33: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`.