diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-05-24 09:23:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-24 09:23:42 +0200 |
| commit | 8019d08ef96014a575ede8cccd130f2b0a56a9d4 (patch) | |
| tree | 532817e1dda879b95f559f9328217726de9c0065 /tests | |
| parent | a89c33b290dc794b7a685c51144cfdea6a4549c4 (diff) | |
| parent | 343fecabc750fa10bc695ad840cfc3ff9bc70830 (diff) | |
| download | rust-8019d08ef96014a575ede8cccd130f2b0a56a9d4.tar.gz rust-8019d08ef96014a575ede8cccd130f2b0a56a9d4.zip | |
Rollup merge of #141456 - Urgau:check-cfg-version-pred, r=jieyouxu
Suggest correct `version("..")` predicate syntax in check-cfg
This PR specialize the `unexpected_cfgs` lint diagnostic to suggest correct `version("..")` predicate syntax when providing the key-value one, eg. `version = "1.27"`.
Fixes https://github.com/rust-lang/rust/issues/141440
r? ``@jieyouxu``
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/check-cfg/wrong-version-syntax.fixed | 14 | ||||
| -rw-r--r-- | tests/ui/check-cfg/wrong-version-syntax.rs | 14 | ||||
| -rw-r--r-- | tests/ui/check-cfg/wrong-version-syntax.stderr | 17 |
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/ui/check-cfg/wrong-version-syntax.fixed b/tests/ui/check-cfg/wrong-version-syntax.fixed new file mode 100644 index 00000000000..efbe2ed1bd8 --- /dev/null +++ b/tests/ui/check-cfg/wrong-version-syntax.fixed @@ -0,0 +1,14 @@ +// Check warning for wrong `cfg(version("1.27"))` syntax +// +//@ check-pass +//@ no-auto-check-cfg +//@ compile-flags: --check-cfg=cfg() +//@ run-rustfix + +#![feature(cfg_version)] + +#[cfg(not(version("1.48.0")))] +//~^ WARNING unexpected `cfg` condition name: `version` +pub fn g() {} + +pub fn main() {} diff --git a/tests/ui/check-cfg/wrong-version-syntax.rs b/tests/ui/check-cfg/wrong-version-syntax.rs new file mode 100644 index 00000000000..221ecf4cae8 --- /dev/null +++ b/tests/ui/check-cfg/wrong-version-syntax.rs @@ -0,0 +1,14 @@ +// Check warning for wrong `cfg(version("1.27"))` syntax +// +//@ check-pass +//@ no-auto-check-cfg +//@ compile-flags: --check-cfg=cfg() +//@ run-rustfix + +#![feature(cfg_version)] + +#[cfg(not(version = "1.48.0"))] +//~^ WARNING unexpected `cfg` condition name: `version` +pub fn g() {} + +pub fn main() {} diff --git a/tests/ui/check-cfg/wrong-version-syntax.stderr b/tests/ui/check-cfg/wrong-version-syntax.stderr new file mode 100644 index 00000000000..97157a0c02b --- /dev/null +++ b/tests/ui/check-cfg/wrong-version-syntax.stderr @@ -0,0 +1,17 @@ +warning: unexpected `cfg` condition name: `version` + --> $DIR/wrong-version-syntax.rs:10:11 + | +LL | #[cfg(not(version = "1.48.0"))] + | ^^^^^^^^^^^^^^^^^^ + | + = help: to expect this configuration use `--check-cfg=cfg(version, values("1.48.0"))` + = note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration + = note: `#[warn(unexpected_cfgs)]` on by default +help: there is a similar config predicate: `version("..")` + | +LL - #[cfg(not(version = "1.48.0"))] +LL + #[cfg(not(version("1.48.0")))] + | + +warning: 1 warning emitted + |
