Add more tests for cfg(version)

This commit is contained in:
mibac138 2020-04-28 16:07:50 +02:00
parent 96f27c73cf
commit a3ee28370f
3 changed files with 53 additions and 5 deletions

View File

@ -652,8 +652,7 @@ pub fn eval_condition(
return false;
}
};
let version = option_env!("CFG_VERSION").unwrap_or("unknown rustc version");
let version = Version::parse(version).unwrap();
let version = Version::parse(env!("CFG_VERSION")).unwrap();
version >= min_version
}

View File

@ -17,14 +17,24 @@ fn bar() -> bool { false }
#[cfg(version("999"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("999"))]
#[cfg(version("-1"))] //~ ERROR: invalid version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("65536"))] //~ ERROR: invalid version literal
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { false }
#[cfg(version("0"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn bar() -> bool { true }
#[cfg(version("1.65536.2"))]
//~^ ERROR `cfg(version)` is experimental and subject to change
fn version_check_bug() {}
fn main() {
// This should fail but due to a bug in version_check `1.65536.2` is interpreted as `1.2`.
// See https://github.com/SergioBenitez/version_check/issues/11
version_check_bug();
assert!(foo());
assert!(bar());
assert!(cfg!(version("1.42"))); //~ ERROR `cfg(version)` is experimental and subject to change

View File

@ -73,6 +73,36 @@ LL | #[cfg(version("999"))]
error[E0658]: `cfg(version)` is experimental and subject to change
--> $DIR/feature-gate-cfg-version.rs:20:7
|
LL | #[cfg(version("-1"))]
| ^^^^^^^^^^^^^
|
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
error: invalid version literal
--> $DIR/feature-gate-cfg-version.rs:20:15
|
LL | #[cfg(version("-1"))]
| ^^^^
error[E0658]: `cfg(version)` is experimental and subject to change
--> $DIR/feature-gate-cfg-version.rs:23:7
|
LL | #[cfg(version("65536"))]
| ^^^^^^^^^^^^^^^^
|
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
error: invalid version literal
--> $DIR/feature-gate-cfg-version.rs:23:15
|
LL | #[cfg(version("65536"))]
| ^^^^^^^
error[E0658]: `cfg(version)` is experimental and subject to change
--> $DIR/feature-gate-cfg-version.rs:26:7
|
LL | #[cfg(version("0"))]
| ^^^^^^^^^^^^
|
@ -80,7 +110,16 @@ LL | #[cfg(version("0"))]
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
error[E0658]: `cfg(version)` is experimental and subject to change
--> $DIR/feature-gate-cfg-version.rs:27:18
--> $DIR/feature-gate-cfg-version.rs:30:7
|
LL | #[cfg(version("1.65536.2"))]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
error[E0658]: `cfg(version)` is experimental and subject to change
--> $DIR/feature-gate-cfg-version.rs:40:18
|
LL | assert!(cfg!(version("1.42")));
| ^^^^^^^^^^^^^^^
@ -88,6 +127,6 @@ LL | assert!(cfg!(version("1.42")));
= note: see issue #64796 <https://github.com/rust-lang/rust/issues/64796> for more information
= help: add `#![feature(cfg_version)]` to the crate attributes to enable
error: aborting due to 11 previous errors
error: aborting due to 16 previous errors
For more information about this error, try `rustc --explain E0658`.