diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2022-03-04 22:58:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-03-04 22:58:34 +0100 |
| commit | afa85f08410aaa874f628c2704818ef2fb126f00 (patch) | |
| tree | dc65aab68cf9b65f14011a7a7807a86dbc8cdf75 /src | |
| parent | 9fcbc32053d5084d1de79bd484de82474cdae427 (diff) | |
| parent | 4aa92aff054c8e89c61ac06551a405af828ade70 (diff) | |
| download | rust-afa85f08410aaa874f628c2704818ef2fb126f00.tar.gz rust-afa85f08410aaa874f628c2704818ef2fb126f00.zip | |
Rollup merge of #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```
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/check-cfg/empty-values.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/check-cfg/empty-values.stderr | 11 | ||||
| -rw-r--r-- | src/test/ui/check-cfg/well-known-values.rs | 28 | ||||
| -rw-r--r-- | src/test/ui/check-cfg/well-known-values.stderr | 31 |
4 files changed, 75 insertions, 3 deletions
diff --git a/src/test/ui/check-cfg/empty-values.rs b/src/test/ui/check-cfg/empty-values.rs index 38ef9e51c7a..9bda42e5d15 100644 --- a/src/test/ui/check-cfg/empty-values.rs +++ b/src/test/ui/check-cfg/empty-values.rs @@ -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() {} diff --git a/src/test/ui/check-cfg/empty-values.stderr b/src/test/ui/check-cfg/empty-values.stderr index 106d5b7b47f..834b28f1244 100644 --- a/src/test/ui/check-cfg/empty-values.stderr +++ b/src/test/ui/check-cfg/empty-values.stderr @@ -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 diff --git a/src/test/ui/check-cfg/well-known-values.rs b/src/test/ui/check-cfg/well-known-values.rs new file mode 100644 index 00000000000..46004be43d8 --- /dev/null +++ b/src/test/ui/check-cfg/well-known-values.rs @@ -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() {} diff --git a/src/test/ui/check-cfg/well-known-values.stderr b/src/test/ui/check-cfg/well-known-values.stderr new file mode 100644 index 00000000000..05b2a8af0ee --- /dev/null +++ b/src/test/ui/check-cfg/well-known-values.stderr @@ -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 + |
