Skip to content

Commit a3ee283

Browse files
committed
Add more tests for cfg(version)
1 parent 96f27c7 commit a3ee283

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

src/librustc_attr/builtin.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,7 @@ pub fn eval_condition(
652652
return false;
653653
}
654654
};
655-
let version = option_env!("CFG_VERSION").unwrap_or("unknown rustc version");
656-
let version = Version::parse(version).unwrap();
655+
let version = Version::parse(env!("CFG_VERSION")).unwrap();
657656

658657
version >= min_version
659658
}

src/test/ui/feature-gates/feature-gate-cfg-version.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ fn bar() -> bool { false }
1717
#[cfg(version("999"))]
1818
//~^ ERROR `cfg(version)` is experimental and subject to change
1919
fn bar() -> bool { false }
20-
#[cfg(version("999"))]
20+
#[cfg(version("-1"))] //~ ERROR: invalid version literal
21+
//~^ ERROR `cfg(version)` is experimental and subject to change
22+
fn bar() -> bool { false }
23+
#[cfg(version("65536"))] //~ ERROR: invalid version literal
2124
//~^ ERROR `cfg(version)` is experimental and subject to change
2225
fn bar() -> bool { false }
2326
#[cfg(version("0"))]
2427
//~^ ERROR `cfg(version)` is experimental and subject to change
2528
fn bar() -> bool { true }
2629

30+
#[cfg(version("1.65536.2"))]
31+
//~^ ERROR `cfg(version)` is experimental and subject to change
32+
fn version_check_bug() {}
33+
2734
fn main() {
35+
// This should fail but due to a bug in version_check `1.65536.2` is interpreted as `1.2`.
36+
// See https://github.com/SergioBenitez/version_check/issues/11
37+
version_check_bug();
2838
assert!(foo());
2939
assert!(bar());
3040
assert!(cfg!(version("1.42"))); //~ ERROR `cfg(version)` is experimental and subject to change

src/test/ui/feature-gates/feature-gate-cfg-version.stderr

+41-2
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,60 @@ LL | #[cfg(version("999"))]
7373
error[E0658]: `cfg(version)` is experimental and subject to change
7474
--> $DIR/feature-gate-cfg-version.rs:20:7
7575
|
76+
LL | #[cfg(version("-1"))]
77+
| ^^^^^^^^^^^^^
78+
|
79+
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
80+
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
81+
82+
error: invalid version literal
83+
--> $DIR/feature-gate-cfg-version.rs:20:15
84+
|
85+
LL | #[cfg(version("-1"))]
86+
| ^^^^
87+
88+
error[E0658]: `cfg(version)` is experimental and subject to change
89+
--> $DIR/feature-gate-cfg-version.rs:23:7
90+
|
91+
LL | #[cfg(version("65536"))]
92+
| ^^^^^^^^^^^^^^^^
93+
|
94+
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
95+
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
96+
97+
error: invalid version literal
98+
--> $DIR/feature-gate-cfg-version.rs:23:15
99+
|
100+
LL | #[cfg(version("65536"))]
101+
| ^^^^^^^
102+
103+
error[E0658]: `cfg(version)` is experimental and subject to change
104+
--> $DIR/feature-gate-cfg-version.rs:26:7
105+
|
76106
LL | #[cfg(version("0"))]
77107
| ^^^^^^^^^^^^
78108
|
79109
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
80110
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
81111

82112
error[E0658]: `cfg(version)` is experimental and subject to change
83-
--> $DIR/feature-gate-cfg-version.rs:27:18
113+
--> $DIR/feature-gate-cfg-version.rs:30:7
114+
|
115+
LL | #[cfg(version("1.65536.2"))]
116+
| ^^^^^^^^^^^^^^^^^^^^
117+
|
118+
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
119+
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
120+
121+
error[E0658]: `cfg(version)` is experimental and subject to change
122+
--> $DIR/feature-gate-cfg-version.rs:40:18
84123
|
85124
LL | assert!(cfg!(version("1.42")));
86125
| ^^^^^^^^^^^^^^^
87126
|
88127
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
89128
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
90129

91-
error: aborting due to 11 previous errors
130+
error: aborting due to 16 previous errors
92131

93132
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)