From 1852141219b39b2a6bb13ad273c96371d58a41e0 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 20 Jun 2024 18:13:48 +1000 Subject: [PATCH] coverage: Bless coverage attribute tests --- tests/ui/coverage-attr/bad-syntax.rs | 39 ++-- tests/ui/coverage-attr/bad-syntax.stderr | 137 ++++++++--- tests/ui/coverage-attr/name-value.rs | 51 ++-- tests/ui/coverage-attr/name-value.stderr | 194 ++++++++++------ tests/ui/coverage-attr/no-coverage.rs | 30 +-- tests/ui/coverage-attr/no-coverage.stderr | 103 +++++---- tests/ui/coverage-attr/subword.rs | 8 +- tests/ui/coverage-attr/subword.stderr | 36 ++- tests/ui/coverage-attr/word-only.rs | 45 ++-- tests/ui/coverage-attr/word-only.stderr | 270 ++++++++++++++++++++-- 10 files changed, 648 insertions(+), 265 deletions(-) diff --git a/tests/ui/coverage-attr/bad-syntax.rs b/tests/ui/coverage-attr/bad-syntax.rs index 127179877e55a..c8c92de8c380f 100644 --- a/tests/ui/coverage-attr/bad-syntax.rs +++ b/tests/ui/coverage-attr/bad-syntax.rs @@ -1,58 +1,45 @@ #![feature(coverage_attribute)] +//@ edition: 2021 // Tests the error messages produced (or not produced) by various unusual // uses of the `#[coverage(..)]` attribute. -// FIXME(#126658): Multiple coverage attributes with the same value are useless, -// and should probably produce a diagnostic. -#[coverage(off)] +#[coverage(off)] //~ ERROR multiple `coverage` attributes #[coverage(off)] fn multiple_consistent() {} -// FIXME(#126658): When there are multiple inconsistent coverage attributes, -// it's unclear which one will prevail. -#[coverage(off)] +#[coverage(off)] //~ ERROR multiple `coverage` attributes #[coverage(on)] fn multiple_inconsistent() {} -#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage] //~ ERROR malformed `coverage` attribute input fn bare_word() {} -// FIXME(#126658): This shows as multiple different errors, one of which suggests -// writing bare `#[coverage]`, which is not allowed. -#[coverage = true] -//~^ ERROR expected `coverage(off)` or `coverage(on)` -//~| ERROR malformed `coverage` attribute input -//~| HELP the following are the possible correct uses -//~| SUGGESTION #[coverage(on|off)] +#[coverage = true] //~ ERROR malformed `coverage` attribute input fn key_value() {} -#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage()] //~ ERROR malformed `coverage` attribute input fn list_empty() {} -#[coverage(off, off)] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(off, off)] //~ ERROR malformed `coverage` attribute input fn list_consistent() {} -#[coverage(off, on)] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(off, on)] //~ ERROR malformed `coverage` attribute input fn list_inconsistent() {} -#[coverage(bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(bogus)] //~ ERROR malformed `coverage` attribute input fn bogus_word() {} -#[coverage(bogus, off)] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(bogus, off)] //~ ERROR malformed `coverage` attribute input fn bogus_word_before() {} -#[coverage(off, bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(off, bogus)] //~ ERROR malformed `coverage` attribute input fn bogus_word_after() {} -#[coverage(off,)] +#[coverage(off,)] // (OK!) fn comma_after() {} -// FIXME(#126658): This shows as multiple different errors. -#[coverage(,off)] -//~^ ERROR expected identifier, found `,` -//~| HELP remove this comma -//~| ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(,off)] //~ ERROR expected identifier, found `,` fn comma_before() {} fn main() {} diff --git a/tests/ui/coverage-attr/bad-syntax.stderr b/tests/ui/coverage-attr/bad-syntax.stderr index f6181d12a9466..a5868fcf19cff 100644 --- a/tests/ui/coverage-attr/bad-syntax.stderr +++ b/tests/ui/coverage-attr/bad-syntax.stderr @@ -1,78 +1,139 @@ error: malformed `coverage` attribute input - --> $DIR/bad-syntax.rs:23:1 - | -LL | #[coverage = true] - | ^^^^^^^^^^^^^^^^^^ - | -help: the following are the possible correct uses - | -LL | #[coverage(on|off)] + --> $DIR/bad-syntax.rs:15:1 | LL | #[coverage] + | ^^^^^^^^^^^ | - -error: expected identifier, found `,` - --> $DIR/bad-syntax.rs:52:12 +help: the following are the possible correct uses | -LL | #[coverage(,off)] - | ^ - | | - | expected identifier - | help: remove this comma +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` +error: malformed `coverage` attribute input --> $DIR/bad-syntax.rs:18:1 | -LL | #[coverage] - | ^^^^^^^^^^^ - -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:23:1 - | LL | #[coverage = true] | ^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:30:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:21:1 | LL | #[coverage()] | ^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:33:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:24:1 | LL | #[coverage(off, off)] | ^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:36:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:27:1 | LL | #[coverage(off, on)] | ^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:39:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:30:1 | LL | #[coverage(bogus)] | ^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:42:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:33:1 | LL | #[coverage(bogus, off)] | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:45:1 +error: malformed `coverage` attribute input + --> $DIR/bad-syntax.rs:36:1 | LL | #[coverage(off, bogus)] | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/bad-syntax.rs:52:1 +error: expected identifier, found `,` + --> $DIR/bad-syntax.rs:42:12 | LL | #[coverage(,off)] - | ^^^^^^^^^^^^^^^^^ + | ^ + | | + | expected identifier + | help: remove this comma + +error: multiple `coverage` attributes + --> $DIR/bad-syntax.rs:7:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/bad-syntax.rs:8:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ + +error: multiple `coverage` attributes + --> $DIR/bad-syntax.rs:11:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ help: remove this attribute + | +note: attribute also specified here + --> $DIR/bad-syntax.rs:12:1 + | +LL | #[coverage(on)] + | ^^^^^^^^^^^^^^^ error: aborting due to 11 previous errors diff --git a/tests/ui/coverage-attr/name-value.rs b/tests/ui/coverage-attr/name-value.rs index 24c329780c59c..cfd78a03e438a 100644 --- a/tests/ui/coverage-attr/name-value.rs +++ b/tests/ui/coverage-attr/name-value.rs @@ -8,57 +8,62 @@ // and in places that cannot have a coverage attribute, to demonstrate the // interaction between multiple errors. -// FIXME(#126658): The error messages for using this syntax are inconsistent -// with the error message in other cases. They also sometimes appear together -// with other errors, and they suggest using the incorrect `#[coverage]` syntax. - -#[coverage = "off"] //~ ERROR malformed `coverage` attribute input +#[coverage = "off"] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure mod my_mod {} mod my_mod_inner { - #![coverage = "off"] //~ ERROR malformed `coverage` attribute input + #![coverage = "off"] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure } #[coverage = "off"] -//~^ ERROR `#[coverage]` must be applied to coverable code -//~| ERROR malformed `coverage` attribute input +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure struct MyStruct; -#[coverage = "off"] //~ ERROR malformed `coverage` attribute input +#[coverage = "off"] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure impl MyStruct { #[coverage = "off"] - //~^ ERROR `#[coverage]` must be applied to coverable code - //~| ERROR malformed `coverage` attribute input + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32 = 7; } -#[coverage = "off"] //~ ERROR malformed `coverage` attribute input +#[coverage = "off"] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure trait MyTrait { #[coverage = "off"] - //~^ ERROR `#[coverage]` must be applied to coverable code - //~| ERROR malformed `coverage` attribute input + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32; #[coverage = "off"] - //~^ ERROR `#[coverage]` must be applied to coverable code - //~| ERROR malformed `coverage` attribute input + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure type T; } -#[coverage = "off"] //~ ERROR malformed `coverage` attribute input +#[coverage = "off"] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure impl MyTrait for MyStruct { #[coverage = "off"] - //~^ ERROR `#[coverage]` must be applied to coverable code - //~| ERROR malformed `coverage` attribute input + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32 = 8; #[coverage = "off"] - //~^ ERROR `#[coverage]` must be applied to coverable code - //~| ERROR malformed `coverage` attribute input + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure type T = (); } #[coverage = "off"] -//~^ ERROR expected `coverage(off)` or `coverage(on)` -//~| ERROR malformed `coverage` attribute input +//~^ ERROR malformed `coverage` attribute input fn main() {} diff --git a/tests/ui/coverage-attr/name-value.stderr b/tests/ui/coverage-attr/name-value.stderr index 90bc3a3b53b3e..caac687c94d01 100644 --- a/tests/ui/coverage-attr/name-value.stderr +++ b/tests/ui/coverage-attr/name-value.stderr @@ -1,28 +1,28 @@ error: malformed `coverage` attribute input - --> $DIR/name-value.rs:15:1 + --> $DIR/name-value.rs:11:1 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] - | ~~~~~~~~~~~~~~~~~~~ -LL | #[coverage] - | ~~~~~~~~~~~ +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:19:5 + --> $DIR/name-value.rs:17:5 | LL | #![coverage = "off"] | ^^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #![coverage(on|off)] - | ~~~~~~~~~~~~~~~~~~~~ -LL | #![coverage] - | ~~~~~~~~~~~~ +LL | #![coverage(off)] + | +LL | #![coverage(on)] + | error: malformed `coverage` attribute input --> $DIR/name-value.rs:22:1 @@ -32,22 +32,22 @@ LL | #[coverage = "off"] | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:29:5 + --> $DIR/name-value.rs:31:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input @@ -58,162 +58,220 @@ LL | #[coverage = "off"] | help: the following are the possible correct uses | -LL | #[coverage(on|off)] - | ~~~~~~~~~~~~~~~~~~~ -LL | #[coverage] - | ~~~~~~~~~~~ +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:37:5 + --> $DIR/name-value.rs:41:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:42:5 + --> $DIR/name-value.rs:46:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:35:1 + --> $DIR/name-value.rs:37:1 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] - | ~~~~~~~~~~~~~~~~~~~ -LL | #[coverage] - | ~~~~~~~~~~~ +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:50:5 + --> $DIR/name-value.rs:56:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:55:5 + --> $DIR/name-value.rs:61:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:48:1 + --> $DIR/name-value.rs:52:1 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] - | ~~~~~~~~~~~~~~~~~~~ -LL | #[coverage] - | ~~~~~~~~~~~ +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | error: malformed `coverage` attribute input - --> $DIR/name-value.rs:61:1 + --> $DIR/name-value.rs:67:1 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ | help: the following are the possible correct uses | -LL | #[coverage(on|off)] +LL | #[coverage(off)] | -LL | #[coverage] +LL | #[coverage(on)] + | + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:11:1 | +LL | #[coverage = "off"] + | ^^^^^^^^^^^^^^^^^^^ +... +LL | mod my_mod {} + | ------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:17:5 + | +LL | / mod my_mod_inner { +LL | | #![coverage = "off"] + | | ^^^^^^^^^^^^^^^^^^^^ +LL | | +LL | | +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure --> $DIR/name-value.rs:22:1 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | struct MyStruct; - | ---------------- not coverable code + | ---------------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:27:1 + | +LL | #[coverage = "off"] + | ^^^^^^^^^^^^^^^^^^^ +... +LL | / impl MyStruct { +LL | | #[coverage = "off"] +LL | | +LL | | +LL | | const X: u32 = 7; +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:37:1 + | +LL | #[coverage = "off"] + | ^^^^^^^^^^^^^^^^^^^ +... +LL | / trait MyTrait { +LL | | #[coverage = "off"] +LL | | +LL | | +... | +LL | | type T; +LL | | } + | |_- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/name-value.rs:37:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:52:1 + | +LL | #[coverage = "off"] + | ^^^^^^^^^^^^^^^^^^^ +... +LL | / impl MyTrait for MyStruct { +LL | | #[coverage = "off"] +LL | | +LL | | +... | +LL | | type T = (); +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:41:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | const X: u32; - | ------------- not coverable code + | ------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/name-value.rs:42:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:46:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | type T; - | ------- not coverable code + | ------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/name-value.rs:29:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:31:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | const X: u32 = 7; - | ----------------- not coverable code + | ----------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/name-value.rs:50:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:56:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | const X: u32 = 8; - | ----------------- not coverable code + | ----------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/name-value.rs:55:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/name-value.rs:61:5 | LL | #[coverage = "off"] | ^^^^^^^^^^^^^^^^^^^ ... LL | type T = (); - | ------------ not coverable code - -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/name-value.rs:61:1 - | -LL | #[coverage = "off"] - | ^^^^^^^^^^^^^^^^^^^ + | ------------ not a function or closure -error: aborting due to 19 previous errors +error: aborting due to 23 previous errors For more information about this error, try `rustc --explain E0788`. diff --git a/tests/ui/coverage-attr/no-coverage.rs b/tests/ui/coverage-attr/no-coverage.rs index 907d25d333e20..5290fccca6100 100644 --- a/tests/ui/coverage-attr/no-coverage.rs +++ b/tests/ui/coverage-attr/no-coverage.rs @@ -2,54 +2,48 @@ #![feature(coverage_attribute)] #![feature(impl_trait_in_assoc_type)] #![warn(unused_attributes)] -#![coverage(off)] -//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly +#![coverage(off)] //~ ERROR attribute should be applied to a function definition or closure -#[coverage(off)] -//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure trait Trait { - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure const X: u32; - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure type T; type U; } -#[coverage(off)] -//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly +#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure impl Trait for () { const X: u32 = 0; - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure type T = Self; - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure type U = impl Trait; //~ ERROR unconstrained opaque type } extern "C" { - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure static X: u32; - #[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure type T; } #[coverage(off)] fn main() { - #[coverage(off)] - //~^ WARN `#[coverage]` may only be applied to function definitions + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure let _ = (); match () { - #[coverage(off)] - //~^ WARN `#[coverage]` may only be applied to function definitions + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure () => (), } - #[coverage(off)] - //~^ WARN `#[coverage]` may only be applied to function definitions + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure return (); } diff --git a/tests/ui/coverage-attr/no-coverage.stderr b/tests/ui/coverage-attr/no-coverage.stderr index a87b0fb49f00e..c5e3b0922cb42 100644 --- a/tests/ui/coverage-attr/no-coverage.stderr +++ b/tests/ui/coverage-attr/no-coverage.stderr @@ -1,101 +1,116 @@ -warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly - --> $DIR/no-coverage.rs:8:1 - | -LL | #[coverage(off)] - | ^^^^^^^^^^^^^^^^ - | -note: the lint level is defined here - --> $DIR/no-coverage.rs:4:9 - | -LL | #![warn(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:7:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | / trait Trait { +LL | | #[coverage(off)] +LL | | const X: u32; +... | +LL | | type U; +LL | | } + | |_- not a function or closure -warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly - --> $DIR/no-coverage.rs:20:1 - | -LL | #[coverage(off)] - | ^^^^^^^^^^^^^^^^ +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:18:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | / impl Trait for () { +LL | | const X: u32 = 0; +LL | | +LL | | #[coverage(off)] +... | +LL | | type U = impl Trait; +LL | | } + | |_- not a function or closure -warning: `#[coverage]` may only be applied to function definitions - --> $DIR/no-coverage.rs:42:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:39:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ +LL | let _ = (); + | ----------- not a function or closure -warning: `#[coverage]` may only be applied to function definitions - --> $DIR/no-coverage.rs:47:9 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:43:9 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ +LL | () => (), + | -------- not a function or closure -warning: `#[coverage]` may only be applied to function definitions - --> $DIR/no-coverage.rs:52:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:47:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ +LL | return (); + | --------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:11:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:9:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | const X: u32; - | ------------- not coverable code + | ------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:14:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:12:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | type T; - | ------- not coverable code + | ------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:25:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:22:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | type T = Self; - | -------------- not coverable code + | -------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:28:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:25:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | type U = impl Trait; - | -------------------- not coverable code + | -------------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:33:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:30:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | static X: u32; - | -------------- not coverable code + | -------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/no-coverage.rs:36:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:33:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | type T; - | ------- not coverable code + | ------- not a function or closure -warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly +error[E0788]: attribute should be applied to a function definition or closure --> $DIR/no-coverage.rs:5:1 | LL | #![coverage(off)] - | ^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ not a function or closure error: unconstrained opaque type - --> $DIR/no-coverage.rs:29:14 + --> $DIR/no-coverage.rs:26: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 7 previous errors; 6 warnings emitted +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0788`. diff --git a/tests/ui/coverage-attr/subword.rs b/tests/ui/coverage-attr/subword.rs index 98b8c25113cbf..16582240b6908 100644 --- a/tests/ui/coverage-attr/subword.rs +++ b/tests/ui/coverage-attr/subword.rs @@ -4,16 +4,16 @@ // Check that yes/no in `#[coverage(yes)]` and `#[coverage(no)]` must be bare // words, not part of a more complicated substructure. -#[coverage(yes(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(yes(milord))] //~ ERROR malformed `coverage` attribute input fn yes_list() {} -#[coverage(no(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(no(milord))] //~ ERROR malformed `coverage` attribute input fn no_list() {} -#[coverage(yes = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(yes = "milord")] //~ ERROR malformed `coverage` attribute input fn yes_key() {} -#[coverage(no = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage(no = "milord")] //~ ERROR malformed `coverage` attribute input fn no_key() {} fn main() {} diff --git a/tests/ui/coverage-attr/subword.stderr b/tests/ui/coverage-attr/subword.stderr index 561573b8ada64..3a106898f8b9c 100644 --- a/tests/ui/coverage-attr/subword.stderr +++ b/tests/ui/coverage-attr/subword.stderr @@ -1,26 +1,54 @@ -error: expected `coverage(off)` or `coverage(on)` +error: malformed `coverage` attribute input --> $DIR/subword.rs:7:1 | LL | #[coverage(yes(milord))] | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` +error: malformed `coverage` attribute input --> $DIR/subword.rs:10:1 | LL | #[coverage(no(milord))] | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` +error: malformed `coverage` attribute input --> $DIR/subword.rs:13:1 | LL | #[coverage(yes = "milord")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ -error: expected `coverage(off)` or `coverage(on)` +error: malformed `coverage` attribute input --> $DIR/subword.rs:16:1 | LL | #[coverage(no = "milord")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | ~~~~~~~~~~~~~~~~ +LL | #[coverage(on)] + | ~~~~~~~~~~~~~~~ error: aborting due to 4 previous errors diff --git a/tests/ui/coverage-attr/word-only.rs b/tests/ui/coverage-attr/word-only.rs index 5c723b1b6b61e..0a61d1e709f51 100644 --- a/tests/ui/coverage-attr/word-only.rs +++ b/tests/ui/coverage-attr/word-only.rs @@ -8,47 +8,62 @@ // and in places that cannot have a coverage attribute, to demonstrate the // interaction between multiple errors. -// FIXME(#126658): The error messages for using this syntax give the impression -// that it is legal, even though it should never be legal. - -// FIXME(#126658): This is silently allowed, but should not be. #[coverage] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure mod my_mod {} -// FIXME(#126658): This is silently allowed, but should not be. mod my_mod_inner { #![coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure } -#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code +#[coverage] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure struct MyStruct; -// FIXME(#126658): This is silently allowed, but should not be. #[coverage] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure impl MyStruct { - #[coverage] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32 = 7; } -// FIXME(#126658): This is silently allowed, but should not be. #[coverage] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure trait MyTrait { - #[coverage] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32; - #[coverage] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure type T; } -// FIXME(#126658): This is silently allowed, but should not be. #[coverage] +//~^ ERROR malformed `coverage` attribute input +//~| ERROR attribute should be applied to a function definition or closure impl MyTrait for MyStruct { - #[coverage] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure const X: u32 = 8; - #[coverage] //~ ERROR `#[coverage]` must be applied to coverable code + #[coverage] + //~^ ERROR malformed `coverage` attribute input + //~| ERROR attribute should be applied to a function definition or closure type T = (); } -#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)` +#[coverage] +//~^ ERROR malformed `coverage` attribute input fn main() {} diff --git a/tests/ui/coverage-attr/word-only.stderr b/tests/ui/coverage-attr/word-only.stderr index bcafc23bc8d7d..18b5fed748476 100644 --- a/tests/ui/coverage-attr/word-only.stderr +++ b/tests/ui/coverage-attr/word-only.stderr @@ -1,57 +1,277 @@ -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:23:1 +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:11:1 | LL | #[coverage] | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:17:5 + | +LL | #![coverage] + | ^^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #![coverage(off)] + | +LL | #![coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:22:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:31:5 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:27:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:41:5 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:46:5 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:37:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:56:5 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:61:5 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:52:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error: malformed `coverage` attribute input + --> $DIR/word-only.rs:67:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ + | +help: the following are the possible correct uses + | +LL | #[coverage(off)] + | +LL | #[coverage(on)] + | + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:11:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ +... +LL | mod my_mod {} + | ------------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:17:5 + | +LL | / mod my_mod_inner { +LL | | #![coverage] + | | ^^^^^^^^^^^^ +LL | | +LL | | +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:22:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ +... LL | struct MyStruct; - | ---------------- not coverable code + | ---------------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:27:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ +... +LL | / impl MyStruct { +LL | | #[coverage] +LL | | +LL | | +LL | | const X: u32 = 7; +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:37:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ +... +LL | / trait MyTrait { +LL | | #[coverage] +LL | | +LL | | +... | +LL | | type T; +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:52:1 + | +LL | #[coverage] + | ^^^^^^^^^^^ +... +LL | / impl MyTrait for MyStruct { +LL | | #[coverage] +LL | | +LL | | +... | +LL | | type T = (); +LL | | } + | |_- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:36:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:41:5 | LL | #[coverage] | ^^^^^^^^^^^ +... LL | const X: u32; - | ------------- not coverable code + | ------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:39:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:46:5 | LL | #[coverage] | ^^^^^^^^^^^ +... LL | type T; - | ------- not coverable code + | ------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:29:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:31:5 | LL | #[coverage] | ^^^^^^^^^^^ +... LL | const X: u32 = 7; - | ----------------- not coverable code + | ----------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:46:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:56:5 | LL | #[coverage] | ^^^^^^^^^^^ +... LL | const X: u32 = 8; - | ----------------- not coverable code + | ----------------- not a function or closure -error[E0788]: `#[coverage]` must be applied to coverable code - --> $DIR/word-only.rs:49:5 +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/word-only.rs:61:5 | LL | #[coverage] | ^^^^^^^^^^^ +... LL | type T = (); - | ------------ not coverable code - -error: expected `coverage(off)` or `coverage(on)` - --> $DIR/word-only.rs:53:1 - | -LL | #[coverage] - | ^^^^^^^^^^^ + | ------------ not a function or closure -error: aborting due to 7 previous errors +error: aborting due to 23 previous errors For more information about this error, try `rustc --explain E0788`.