forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#126659 - Zalathar:test-coverage-attr, r=cjg…
…illot More status-quo tests for the `#[coverage(..)]` attribute Follow-up to rust-lang#126621, after I found even more weird corner-cases in the handling of the coverage attribute. These tests reveal some inconsistencies that are tracked by rust-lang#126658.
- Loading branch information
Showing
7 changed files
with
443 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#![feature(coverage_attribute)] | ||
//@ edition: 2021 | ||
|
||
// Demonstrates the diagnostics produced when using the syntax | ||
// `#[coverage = "off"]`, which should not be allowed. | ||
// | ||
// The syntax is tested both in places that can have a coverage attribute, | ||
// 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 | ||
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
error: malformed `coverage` attribute input | ||
--> $DIR/name-value.rs:15: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:19: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:22: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:29: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:27: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:37: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:42: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:35: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:50: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:55: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:48: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:61: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:22:1 | ||
| | ||
LL | #[coverage = "off"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | struct MyStruct; | ||
| ---------------- not coverable code | ||
|
||
error[E0788]: `#[coverage]` must be applied to coverable code | ||
--> $DIR/name-value.rs:37:5 | ||
| | ||
LL | #[coverage = "off"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | const X: u32; | ||
| ------------- not coverable code | ||
|
||
error[E0788]: `#[coverage]` must be applied to coverable code | ||
--> $DIR/name-value.rs:42:5 | ||
| | ||
LL | #[coverage = "off"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | type T; | ||
| ------- not coverable code | ||
|
||
error[E0788]: `#[coverage]` must be applied to coverable code | ||
--> $DIR/name-value.rs:29: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:50: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:55: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"] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 19 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0788`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![feature(coverage_attribute)] | ||
//@ edition: 2021 | ||
|
||
// 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)` | ||
fn yes_list() {} | ||
|
||
#[coverage(no(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)` | ||
fn no_list() {} | ||
|
||
#[coverage(yes = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` | ||
fn yes_key() {} | ||
|
||
#[coverage(no = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` | ||
fn no_key() {} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
error: expected `coverage(off)` or `coverage(on)` | ||
--> $DIR/subword.rs:7:1 | ||
| | ||
LL | #[coverage(yes(milord))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: expected `coverage(off)` or `coverage(on)` | ||
--> $DIR/subword.rs:10:1 | ||
| | ||
LL | #[coverage(no(milord))] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: expected `coverage(off)` or `coverage(on)` | ||
--> $DIR/subword.rs:13:1 | ||
| | ||
LL | #[coverage(yes = "milord")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: expected `coverage(off)` or `coverage(on)` | ||
--> $DIR/subword.rs:16:1 | ||
| | ||
LL | #[coverage(no = "milord")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
Oops, something went wrong.