Skip to content

Commit f294432

Browse files
committed
Add functional #[cfg(version)] test
1 parent 6adbece commit f294432

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ run-pass
2+
//@ rustc-env:RUSTC_OVERRIDE_VERSION_STRING=1.50.3
3+
4+
#![feature(cfg_version)]
5+
6+
#[cfg(version("1.49.0"))]
7+
const ON_1_49_0: bool = true;
8+
#[cfg(version("1.50"))]
9+
const ON_1_50_0: bool = true;
10+
#[cfg(not(version("1.51")))]
11+
const ON_1_51_0: bool = false;
12+
13+
// This one uses the wrong syntax, so doesn't eval to true
14+
#[warn(unexpected_cfgs)]
15+
#[cfg(not(version = "1.48.0"))] //~ WARN unexpected `cfg` condition name: `version`
16+
const ON_1_48_0: bool = false;
17+
18+
fn main() {
19+
assert!(!ON_1_48_0);
20+
assert!(ON_1_49_0);
21+
assert!(ON_1_50_0);
22+
assert!(!ON_1_51_0);
23+
assert!(cfg!(version("1.1")));
24+
assert!(cfg!(version("1.49")));
25+
assert!(cfg!(version("1.50.0")));
26+
assert!(cfg!(version("1.50.3")));
27+
assert!(!cfg!(version("1.50.4")));
28+
assert!(!cfg!(version("1.51")));
29+
assert!(!cfg!(version("1.100")));
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
warning: unexpected `cfg` condition name: `version`
2+
--> $DIR/cfg-version-expand.rs:15:11
3+
|
4+
LL | #[cfg(not(version = "1.48.0"))]
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: expected names are: `FALSE` and `test` and 31 more
8+
= help: to expect this configuration use `--check-cfg=cfg(version, values("1.48.0"))`
9+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
10+
= note: `#[warn(unexpected_cfgs)]` on by default
11+
12+
warning: 1 warning emitted
13+

0 commit comments

Comments
 (0)