Skip to content

Commit

Permalink
Rollup merge of rust-lang#117025 - Urgau:cleanup-improve-check-cfg-im…
Browse files Browse the repository at this point in the history
…pl, r=petrochenkov

Cleanup and improve `--check-cfg` implementation

This PR removes some indentation in the code, as well as preventing some bugs/misusages and fix a nit in the doc.

r? ``@petrochenkov`` (maybe)
  • Loading branch information
TaKO8Ki committed Oct 27, 2023
2 parents f8807cc + e2122e7 commit 15c3b76
Show file tree
Hide file tree
Showing 17 changed files with 277 additions and 297 deletions.
398 changes: 198 additions & 200 deletions compiler/rustc_interface/src/interface.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/doc/unstable-book/src/compiler-flags/check-cfg.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn do_mumble_frotz() {}

```bash
# This turns on checking for feature values, but not for condition names.
rustc --check-cfg 'configure(feature, values("zapping", "lasers"))' \
rustc --check-cfg 'cfg(feature, values("zapping", "lasers"))' \
--check-cfg 'cfg(any())' \
--cfg 'feature="zapping"' -Z unstable-options
```
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/invalid-arguments.any_values.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: invalid `--check-cfg` argument: `cfg(any(),values())` (`values()` cannot be specified before the names)

4 changes: 3 additions & 1 deletion tests/ui/check-cfg/invalid-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// revisions: multiple_values_any not_empty_any not_empty_values_any
// revisions: values_any_missing_values values_any_before_ident ident_in_values_1
// revisions: ident_in_values_2 unknown_meta_item_1 unknown_meta_item_2 unknown_meta_item_3
// revisions: mixed_values_any mixed_any giberich
// revisions: mixed_values_any mixed_any any_values giberich unterminated
//
// compile-flags: -Z unstable-options
// [anything_else]compile-flags: --check-cfg=anything_else(...)
Expand All @@ -29,6 +29,8 @@
// [unknown_meta_item_3]compile-flags: --check-cfg=cfg(foo,values(test()))
// [mixed_values_any]compile-flags: --check-cfg=cfg(foo,values("bar",any()))
// [mixed_any]compile-flags: --check-cfg=cfg(any(),values(any()))
// [any_values]compile-flags: --check-cfg=cfg(any(),values())
// [giberich]compile-flags: --check-cfg=cfg(...)
// [unterminated]compile-flags: --check-cfg=cfg(

fn main() {}
2 changes: 2 additions & 0 deletions tests/ui/check-cfg/invalid-arguments.unterminated.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: invalid `--check-cfg` argument: `cfg(` (expected `cfg(name, values("value1", "value2", ... "valueN"))`)

52 changes: 26 additions & 26 deletions tests/ui/check-cfg/mix.cfg.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
warning: unexpected `cfg` condition name: `widnows`
--> $DIR/mix.rs:15:7
--> $DIR/mix.rs:16:7
|
LL | #[cfg(widnows)]
| ^^^^^^^ help: there is a config with a similar name: `windows`
|
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition value: (none)
--> $DIR/mix.rs:19:7
--> $DIR/mix.rs:20:7
|
LL | #[cfg(feature)]
| ^^^^^^^- help: specify a config value: `= "foo"`
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `bar`
--> $DIR/mix.rs:26:7
--> $DIR/mix.rs:27:7
|
LL | #[cfg(feature = "bar")]
| ^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:30:7
--> $DIR/mix.rs:31:7
|
LL | #[cfg(feature = "zebra")]
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition name: `uu`
--> $DIR/mix.rs:34:12
--> $DIR/mix.rs:35:12
|
LL | #[cfg_attr(uu, test)]
| ^^
Expand All @@ -47,141 +47,141 @@ warning: unexpected `unknown_name` as condition name
= help: was set with `--cfg` but isn't in the `--check-cfg` expected names

warning: unexpected `cfg` condition name: `widnows`
--> $DIR/mix.rs:43:10
--> $DIR/mix.rs:44:10
|
LL | cfg!(widnows);
| ^^^^^^^ help: there is a config with a similar name: `windows`

warning: unexpected `cfg` condition value: `bar`
--> $DIR/mix.rs:46:10
--> $DIR/mix.rs:47:10
|
LL | cfg!(feature = "bar");
| ^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:48:10
--> $DIR/mix.rs:49:10
|
LL | cfg!(feature = "zebra");
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:50:10
--> $DIR/mix.rs:51:10
|
LL | cfg!(xxx = "foo");
| ^^^^^^^^^^^

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:52:10
--> $DIR/mix.rs:53:10
|
LL | cfg!(xxx);
| ^^^

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:54:14
--> $DIR/mix.rs:55:14
|
LL | cfg!(any(xxx, windows));
| ^^^

warning: unexpected `cfg` condition value: `bad`
--> $DIR/mix.rs:56:14
--> $DIR/mix.rs:57:14
|
LL | cfg!(any(feature = "bad", windows));
| ^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:58:23
--> $DIR/mix.rs:59:23
|
LL | cfg!(any(windows, xxx));
| ^^^

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:60:20
--> $DIR/mix.rs:61:20
|
LL | cfg!(all(unix, xxx));
| ^^^

warning: unexpected `cfg` condition name: `aa`
--> $DIR/mix.rs:62:14
--> $DIR/mix.rs:63:14
|
LL | cfg!(all(aa, bb));
| ^^

warning: unexpected `cfg` condition name: `bb`
--> $DIR/mix.rs:62:18
--> $DIR/mix.rs:63:18
|
LL | cfg!(all(aa, bb));
| ^^

warning: unexpected `cfg` condition name: `aa`
--> $DIR/mix.rs:65:14
--> $DIR/mix.rs:66:14
|
LL | cfg!(any(aa, bb));
| ^^

warning: unexpected `cfg` condition name: `bb`
--> $DIR/mix.rs:65:18
--> $DIR/mix.rs:66:18
|
LL | cfg!(any(aa, bb));
| ^^

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:68:20
--> $DIR/mix.rs:69:20
|
LL | cfg!(any(unix, feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:70:14
--> $DIR/mix.rs:71:14
|
LL | cfg!(any(xxx, feature = "zebra"));
| ^^^

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:70:19
--> $DIR/mix.rs:71:19
|
LL | cfg!(any(xxx, feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:73:14
--> $DIR/mix.rs:74:14
|
LL | cfg!(any(xxx, unix, xxx));
| ^^^

warning: unexpected `cfg` condition name: `xxx`
--> $DIR/mix.rs:73:25
--> $DIR/mix.rs:74:25
|
LL | cfg!(any(xxx, unix, xxx));
| ^^^

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:76:14
--> $DIR/mix.rs:77:14
|
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:76:33
--> $DIR/mix.rs:77:33
|
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
|
= note: expected values for `feature` are: `foo`

warning: unexpected `cfg` condition value: `zebra`
--> $DIR/mix.rs:76:52
--> $DIR/mix.rs:77:52
|
LL | cfg!(all(feature = "zebra", feature = "zebra", feature = "zebra"));
| ^^^^^^^^^^^^^^^^^
Expand Down
Loading

0 comments on commit 15c3b76

Please sign in to comment.