Skip to content

Commit

Permalink
More status-quo tests for the #[coverage(..)] attribute
Browse files Browse the repository at this point in the history
These tests reveal some inconsistencies that are tracked by
<rust-lang#126658>.
  • Loading branch information
Zalathar committed Jun 19, 2024
1 parent 8fcd4dd commit a0d4c4d
Show file tree
Hide file tree
Showing 5 changed files with 387 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/ui/coverage-attr/bad-syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Tests the error messages produced (or not produced) by various unusual
// uses of the `#[coverage(..)]` attribute.

// FIXME(#84605): Multiple coverage attributes with the same value are useless,
// FIXME(#126658): Multiple coverage attributes with the same value are useless,
// and should probably produce a diagnostic.
#[coverage(off)]
#[coverage(off)]
fn multiple_consistent() {}

// FIXME(#84605): When there are multiple inconsistent coverage attributes,
// FIXME(#126658): When there are multiple inconsistent coverage attributes,
// it's unclear which one will prevail.
#[coverage(off)]
#[coverage(on)]
Expand All @@ -18,7 +18,7 @@ fn multiple_inconsistent() {}
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
fn bare_word() {}

// FIXME(#84605): This shows as multiple different errors, one of which suggests
// 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)`
Expand Down Expand Up @@ -48,7 +48,7 @@ fn bogus_word_after() {}
#[coverage(off,)]
fn comma_after() {}

// FIXME(#84605): This shows as multiple different errors.
// FIXME(#126658): This shows as multiple different errors.
#[coverage(,off)]
//~^ ERROR expected identifier, found `,`
//~| HELP remove this comma
Expand Down
60 changes: 60 additions & 0 deletions tests/ui/coverage-attr/name-value.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Demonstrates the diagnostics produced when using the syntax
// `#![coverage = "off"]`, which should not be allowed.

// 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
mod my_mod {}

mod my_mod_inner {
#![coverage = "off"] //~ ERROR malformed `coverage` attribute input
}

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
struct MyStruct;

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
impl MyStruct {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
const X: u32 = 7;
}

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
trait MyTrait {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
const X: u32;

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
type T;
}

#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
impl MyTrait for MyStruct {
#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
const X: u32 = 8;

#[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code
//~| ERROR malformed `coverage` attribute input
type T = ();
}

#[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR malformed `coverage` attribute input
fn main() {}
219 changes: 219 additions & 0 deletions tests/ui/coverage-attr/name-value.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
error: malformed `coverage` attribute input
--> $DIR/name-value.rs:11:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
| ~~~~~~~~~~~~~~~~~~~
LL | #[coverage]
| ~~~~~~~~~~~

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:15:5
|
LL | #![coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #![coverage(on|off)]
| ~~~~~~~~~~~~~~~~~~~~
LL | #![coverage]
| ~~~~~~~~~~~~

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:18:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:25:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:23:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
| ~~~~~~~~~~~~~~~~~~~
LL | #[coverage]
| ~~~~~~~~~~~

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:33:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:38:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:31:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
| ~~~~~~~~~~~~~~~~~~~
LL | #[coverage]
| ~~~~~~~~~~~

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:46:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:51:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:44:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
| ~~~~~~~~~~~~~~~~~~~
LL | #[coverage]
| ~~~~~~~~~~~

error: malformed `coverage` attribute input
--> $DIR/name-value.rs:57:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(on|off)]
|
LL | #[coverage]
|

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:18:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | struct MyStruct;
| ---------------- not coverable code

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:33:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | const X: u32;
| ------------- not coverable code

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:38:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | type T;
| ------- not coverable code

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:25:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | const X: u32 = 7;
| ----------------- not coverable code

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:46:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | const X: u32 = 8;
| ----------------- not coverable code

error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/name-value.rs:51:5
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | type T = ();
| ------------ not coverable code

error: expected `coverage(off)` or `coverage(on)`
--> $DIR/name-value.rs:57:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 19 previous errors

For more information about this error, try `rustc --explain E0788`.
47 changes: 47 additions & 0 deletions tests/ui/coverage-attr/word-only.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#![feature(coverage_attribute)]
//@ edition: 2021

// Demonstrates the diagnostics produced when using the syntax `#![coverage]`,
// which should not be allowed.

// FIXME(#126658): This is silently allowed, but should not be.
#[coverage]
mod my_mod {}

// FIXME(#126658): This is silently allowed, but should not be.
mod my_mod_inner {
#![coverage]
}

#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
struct MyStruct;

// FIXME(#126658): This is silently allowed, but should not be.
#[coverage]
impl MyStruct {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
const X: u32 = 7;
}

// FIXME(#126658): This is silently allowed, but should not be.
#[coverage]
trait MyTrait {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
const X: u32;

#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
type T;
}

// FIXME(#126658): This is silently allowed, but should not be.
#[coverage]
impl MyTrait for MyStruct {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
const X: u32 = 8;

#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
type T = ();
}

#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
fn main() {}
Loading

0 comments on commit a0d4c4d

Please sign in to comment.