forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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#94362 - Urgau:check-cfg-values, r=petrochenkov
Add well known values to `--check-cfg` implementation This pull-request adds well known values for the well known names via `--check-cfg=values()`. [RFC 3013: Checking conditional compilation at compile time](https://rust-lang.github.io/rfcs/3013-conditional-compilation-checking.html#checking-conditional-compilation-at-compile-time) doesn't define this at all, but this seems a nice improvement. The activation is done by a empty `values()` (new syntax) similar to `names()` except that `names(foo)` also activate well known names while `values(aa, "aa", "kk")` would not. As stated this use a different activation logic because well known values for the well known names are not always sufficient. In fact this is problematic for every `target_*` cfg because of non builtin targets, as the current implementation use those built-ins targets to create the list the well known values. The implementation is straight forward, first we gather (if necessary) all the values (lazily or not) and then we apply them. r? `@petrochenkov`
- Loading branch information
Showing
8 changed files
with
207 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
// Check that a an empty values() is rejected | ||
// Check warning for unexpected cfg value | ||
// | ||
// check-fail | ||
// check-pass | ||
// compile-flags: --check-cfg=values() -Z unstable-options | ||
|
||
#[cfg(test = "value")] | ||
//~^ WARNING unexpected `cfg` condition value | ||
pub fn f() {} | ||
|
||
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 |
---|---|---|
@@ -1,2 +1,11 @@ | ||
error: invalid `--check-cfg` argument: `values()` (expected `names(name1, name2, ... nameN)` or `values(name, "value1", "value2", ... "valueN")`) | ||
warning: unexpected `cfg` condition value | ||
--> $DIR/empty-values.rs:6:7 | ||
| | ||
LL | #[cfg(test = "value")] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unexpected_cfgs)]` on by default | ||
= note: no expected value for `test` | ||
|
||
warning: 1 warning emitted | ||
|
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,28 @@ | ||
// This test check that we lint on non well known values and that we don't lint on well known | ||
// values | ||
// | ||
// check-pass | ||
// compile-flags: --check-cfg=values() -Z unstable-options | ||
|
||
#[cfg(target_os = "linuz")] | ||
//~^ WARNING unexpected `cfg` condition value | ||
fn target_os_linux_misspell() {} | ||
|
||
#[cfg(target_os = "linux")] | ||
fn target_os_linux() {} | ||
|
||
#[cfg(target_has_atomic = "0")] | ||
//~^ WARNING unexpected `cfg` condition value | ||
fn target_has_atomic_invalid() {} | ||
|
||
#[cfg(target_has_atomic = "8")] | ||
fn target_has_atomic() {} | ||
|
||
#[cfg(unix = "aa")] | ||
//~^ WARNING unexpected `cfg` condition value | ||
fn unix_with_value() {} | ||
|
||
#[cfg(unix)] | ||
fn unix() {} | ||
|
||
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,31 @@ | ||
warning: unexpected `cfg` condition value | ||
--> $DIR/well-known-values.rs:7:7 | ||
| | ||
LL | #[cfg(target_os = "linuz")] | ||
| ^^^^^^^^^^^^------- | ||
| | | ||
| help: did you mean: `"linux"` | ||
| | ||
= note: `#[warn(unexpected_cfgs)]` on by default | ||
= note: expected values for `target_os` are: android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vxworks, wasi, windows | ||
|
||
warning: unexpected `cfg` condition value | ||
--> $DIR/well-known-values.rs:14:7 | ||
| | ||
LL | #[cfg(target_has_atomic = "0")] | ||
| ^^^^^^^^^^^^^^^^^^^^--- | ||
| | | ||
| help: did you mean: `"8"` | ||
| | ||
= note: expected values for `target_has_atomic` are: 128, 16, 32, 64, 8, ptr | ||
|
||
warning: unexpected `cfg` condition value | ||
--> $DIR/well-known-values.rs:21:7 | ||
| | ||
LL | #[cfg(unix = "aa")] | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: no expected value for `unix` | ||
|
||
warning: 3 warnings emitted | ||
|