Skip to content

Commit 01fe331

Browse files
committed
Add functional #[cfg(version)] test
1 parent ebf5ebc commit 01fe331

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//@ run-pass
2+
//@ rustc-env:RUSTC_OVERRIDE_VERSION_STRING=1.50.3
3+
4+
#[cfg(version("1.49.0"))]
5+
const ON_1_49_0: bool = true;
6+
#[cfg(version("1.50"))]
7+
const ON_1_50_0: bool = true;
8+
#[cfg(not(version("1.51")))]
9+
const ON_1_51_0: bool = false;
10+
11+
// This one uses the wrong syntax, so doesn't eval to true
12+
#[warn(unexpected_cfgs)]
13+
#[cfg(not(version = "1.48.0"))] //~ WARN unexpected `cfg` condition name: `version`
14+
const ON_1_48_0: bool = false;
15+
16+
fn main() {
17+
assert!(!ON_1_48_0);
18+
assert!(ON_1_49_0);
19+
assert!(ON_1_50_0);
20+
assert!(!ON_1_51_0);
21+
assert!(cfg!(version("1.1")));
22+
assert!(cfg!(version("1.49")));
23+
assert!(cfg!(version("1.50.0")));
24+
assert!(cfg!(version("1.50.3")));
25+
assert!(!cfg!(version("1.50.4")));
26+
assert!(!cfg!(version("1.51")));
27+
assert!(!cfg!(version("1.100")));
28+
}
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:13: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)