Skip to content

Commit

Permalink
Add check-cfg test for Cargo feature without value
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau authored and quininer committed Dec 31, 2023
1 parent 707614b commit 72a7707
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
15 changes: 12 additions & 3 deletions tests/ui/check-cfg/cargo-feature.none.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ LL | #[cfg(feature = "serde")]
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `tokio_unstable`
warning: unexpected `cfg` condition name: `feature`
--> $DIR/cargo-feature.rs:18:7
|
LL | #[cfg(feature)]
| ^^^^^^^
|
= help: consider defining some features in `Cargo.toml`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: unexpected `cfg` condition name: `tokio_unstable`
--> $DIR/cargo-feature.rs:23:7
|
LL | #[cfg(tokio_unstable)]
| ^^^^^^^^^^^^^^
|
Expand All @@ -19,13 +28,13 @@ LL | #[cfg(tokio_unstable)]
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: unexpected `cfg` condition name: `CONFIG_NVME`
--> $DIR/cargo-feature.rs:22:7
--> $DIR/cargo-feature.rs:27:7
|
LL | #[cfg(CONFIG_NVME = "m")]
| ^^^^^^^^^^^^^^^^^
|
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of a `build.rs`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: 3 warnings emitted
warning: 4 warnings emitted

5 changes: 5 additions & 0 deletions tests/ui/check-cfg/cargo-feature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
//[some]~^^ WARNING unexpected `cfg` condition value
fn ser() {}

#[cfg(feature)]
//[none]~^ WARNING unexpected `cfg` condition name
//[some]~^^ WARNING unexpected `cfg` condition value
fn feat() {}

#[cfg(tokio_unstable)]
//~^ WARNING unexpected `cfg` condition name
fn tokio() {}
Expand Down
16 changes: 13 additions & 3 deletions tests/ui/check-cfg/cargo-feature.some.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ LL | #[cfg(feature = "serde")]
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `tokio_unstable`
warning: unexpected `cfg` condition value: (none)
--> $DIR/cargo-feature.rs:18:7
|
LL | #[cfg(feature)]
| ^^^^^^^
|
= note: expected values for `feature` are: `bitcode`
= help: consider defining `feature` as feature in `Cargo.toml`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: unexpected `cfg` condition name: `tokio_unstable`
--> $DIR/cargo-feature.rs:23:7
|
LL | #[cfg(tokio_unstable)]
| ^^^^^^^^^^^^^^
|
Expand All @@ -20,7 +30,7 @@ LL | #[cfg(tokio_unstable)]
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: unexpected `cfg` condition value: `m`
--> $DIR/cargo-feature.rs:22:7
--> $DIR/cargo-feature.rs:27:7
|
LL | #[cfg(CONFIG_NVME = "m")]
| ^^^^^^^^^^^^^^---
Expand All @@ -31,5 +41,5 @@ LL | #[cfg(CONFIG_NVME = "m")]
= help: consider using a Cargo feature instead or adding `println!("cargo:rustc-check-cfg=cfg(CONFIG_NVME, values(\"m\"))");` to the top of a `build.rs`
= note: see <https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg> for more information about checking conditional configuration

warning: 3 warnings emitted
warning: 4 warnings emitted

0 comments on commit 72a7707

Please sign in to comment.