-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #126682 - Zalathar:coverage-attr, r=lcnr
coverage: Overhaul validation of the `#[coverage(..)]` attribute This PR makes sweeping changes to how the (currently-unstable) coverage attribute is validated: - Multiple coverage attributes on the same item/expression are now treated as an error. - The attribute must always be `#[coverage(off)]` or `#[coverage(on)]`, and the error messages for this are more consistent. - A trailing comma is still allowed after off/on, since that's part of the normal attribute syntax. - Some places that silently ignored a coverage attribute now produce an error instead. - These cases were all clearly bugs. - Some places that ignored a coverage attribute (with a warning) now produce an error instead. - These were originally added as lints, but I don't think it makes much sense to knowingly allow new attributes to be used in meaningless places. - Some of these errors might soon disappear, if it's easy to extend recursive coverage attributes to things like modules and impl blocks. --- One of the goals of this PR is to lay a more solid foundation for making the coverage attribute recursive, so that it applies to all nested functions/closures instead of just the one it is directly attached to. Fixes #126658. This PR incorporates #126659, which adds more tests for validation of the coverage attribute. `@rustbot` label +A-code-coverage
- Loading branch information
Showing
18 changed files
with
687 additions
and
358 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
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
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
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
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 |
---|---|---|
@@ -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() {} |
Oops, something went wrong.