Rollup merge of #84871 - richkadel:no-coverage-unstable-only, r=nagisa

Disallows `#![feature(no_coverage)]` on stable and beta (using standard crate-level gating)

Fixes: #84836

Removes the function-level feature gating solution originally implemented, and solves the same problem using `allow_internal_unstable`, so normal crate-level feature gating mechanism can still be used (which disallows the feature on stable and beta).

I tested this, building the compiler with and without `CFG_DISABLE_UNSTABLE_FEATURES=1`

With unstable features disabled, I get the expected result as shown here:

```shell
$ ./build/x86_64-unknown-linux-gnu/stage1/bin/rustc     src/test/run-make-fulldeps/coverage/no_cov_crate.rs
error[E0554]: `#![feature]` may not be used on the dev release channel
 --> src/test/run-make-fulldeps/coverage/no_cov_crate.rs:2:1
  |
2 | #![feature(no_coverage)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0554`.
```

r? ````@Mark-Simulacrum````
cc: ````@tmandry```` ````@wesleywiser````
This commit is contained in:
Dylan DPC 2021-05-07 00:38:40 +02:00 committed by GitHub
commit aaf23892ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 18 additions and 91 deletions

View file

@ -1,19 +0,0 @@
1| |// Enables `no_coverage` on individual functions
2| |
3| |#[feature(no_coverage)]
4| |#[no_coverage]
5| |fn do_not_add_coverage_1() {
6| | println!("called but not covered");
7| |}
8| |
9| |#[no_coverage]
10| |#[feature(no_coverage)]
11| |fn do_not_add_coverage_2() {
12| | println!("called but not covered");
13| |}
14| |
15| 1|fn main() {
16| 1| do_not_add_coverage_1();
17| 1| do_not_add_coverage_2();
18| 1|}

View file

@ -1,18 +0,0 @@
// Enables `no_coverage` on individual functions
#[feature(no_coverage)]
#[no_coverage]
fn do_not_add_coverage_1() {
println!("called but not covered");
}
#[no_coverage]
#[feature(no_coverage)]
fn do_not_add_coverage_2() {
println!("called but not covered");
}
fn main() {
do_not_add_coverage_1();
do_not_add_coverage_2();
}

View file

@ -1,8 +1,13 @@
#![crate_type = "lib"]
#[no_coverage]
#[feature(no_coverage)] // does not have to be enabled before `#[no_coverage]`
fn no_coverage_is_enabled_on_this_function() {}
#[derive(PartialEq, Eq)] // ensure deriving `Eq` does not enable `feature(no_coverage)`
struct Foo {
a: u8,
b: u32,
}
#[no_coverage] //~ ERROR the `#[no_coverage]` attribute is an experimental feature
fn requires_feature_no_coverage() {}
fn requires_feature_no_coverage() -> bool {
let bar = Foo { a: 0, b: 0 };
bar == Foo { a: 0, b: 0 }
}

View file

@ -1,12 +1,11 @@
error[E0658]: the `#[no_coverage]` attribute is an experimental feature
--> $DIR/feature-gate-no_coverage.rs:7:1
--> $DIR/feature-gate-no_coverage.rs:9:1
|
LL | #[no_coverage]
| ^^^^^^^^^^^^^^
|
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
= help: add `#![feature(no_coverage)]` to the crate attributes to enable
= help: or, alternatively, add `#[feature(no_coverage)]` to the function
error: aborting due to previous error