diff --git a/tests/coverage/attr/trait-impl-inherit.cov-map b/tests/coverage/attr/trait-impl-inherit.cov-map new file mode 100644 index 0000000000000..eab9f926bb776 --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.cov-map @@ -0,0 +1,9 @@ +Function name: ::f +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 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 + 17, 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 new file mode 100644 index 0000000000000..b92d82aefbc8c --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.coverage @@ -0,0 +1,26 @@ + LL| |#![feature(coverage_attribute)] + 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 { + LL| | #[coverage(off)] + LL| | fn f(&self) { + LL| | println!("default"); + LL| | } + LL| |} + LL| | + LL| |struct S; + LL| | + LL| |impl T for S { + LL| 1| fn f(&self) { + LL| 1| println!("impl S"); + LL| 1| } + LL| |} + LL| | + LL| |#[coverage(off)] + LL| |fn main() { + LL| | S.f(); + LL| |} + diff --git a/tests/coverage/attr/trait-impl-inherit.rs b/tests/coverage/attr/trait-impl-inherit.rs new file mode 100644 index 0000000000000..951fecce90a18 --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.rs @@ -0,0 +1,25 @@ +#![feature(coverage_attribute)] +// Checks that `#[coverage(..)]` in a trait method is not inherited in an +// implementation. +//@ edition: 2021 +//@ reference: attributes.coverage.trait-impl-inherit + +trait T { + #[coverage(off)] + fn f(&self) { + println!("default"); + } +} + +struct S; + +impl T for S { + fn f(&self) { + println!("impl S"); + } +} + +#[coverage(off)] +fn main() { + S.f(); +} diff --git a/tests/ui/coverage-attr/no-coverage.rs b/tests/ui/coverage-attr/no-coverage.rs index d715ec8a3028e..c386f25816e4c 100644 --- a/tests/ui/coverage-attr/no-coverage.rs +++ b/tests/ui/coverage-attr/no-coverage.rs @@ -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)] @@ -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" { diff --git a/tests/ui/coverage-attr/no-coverage.stderr b/tests/ui/coverage-attr/no-coverage.stderr index 1412b54b8d778..f5a44ecec747f 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:41:5 + --> $DIR/no-coverage.rs:50: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:45:9 + --> $DIR/no-coverage.rs:54: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:49:5 + --> $DIR/no-coverage.rs:58: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: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)] | ^^^^^^^^^^^^^^^^ @@ -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:27:5 + --> $DIR/no-coverage.rs:33: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:32:5 + --> $DIR/no-coverage.rs:41: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:35:5 + --> $DIR/no-coverage.rs:44:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -84,13 +100,13 @@ 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`.