|
10 | 10 | use proc_macro::*; |
11 | 11 | use std::path::Path; |
12 | 12 | use std::process::Command; |
13 | | -use std::sync::Once; |
| 13 | +use std::sync::LazyLock; |
14 | 14 |
|
15 | 15 | /// Replacement for `#[test]` |
16 | 16 | /// |
@@ -254,23 +254,21 @@ fn to_token_stream(code: &str) -> TokenStream { |
254 | 254 | code.parse().unwrap() |
255 | 255 | } |
256 | 256 |
|
257 | | -static mut VERSION: (u32, bool) = (0, false); |
| 257 | +static VERSION: std::sync::LazyLock<(u32, bool)> = LazyLock::new(|| { |
| 258 | + let output = Command::new("rustc") |
| 259 | + .arg("-V") |
| 260 | + .output() |
| 261 | + .expect("rustc should run"); |
| 262 | + let stdout = std::str::from_utf8(&output.stdout).expect("utf8"); |
| 263 | + let vers = stdout.split_whitespace().skip(1).next().unwrap(); |
| 264 | + let is_nightly = option_env!("CARGO_TEST_DISABLE_NIGHTLY").is_none() |
| 265 | + && (vers.contains("-nightly") || vers.contains("-dev")); |
| 266 | + let minor = vers.split('.').skip(1).next().unwrap().parse().unwrap(); |
| 267 | + (minor, is_nightly) |
| 268 | +}); |
258 | 269 |
|
259 | 270 | fn version() -> (u32, bool) { |
260 | | - static INIT: Once = Once::new(); |
261 | | - INIT.call_once(|| { |
262 | | - let output = Command::new("rustc") |
263 | | - .arg("-V") |
264 | | - .output() |
265 | | - .expect("rustc should run"); |
266 | | - let stdout = std::str::from_utf8(&output.stdout).expect("utf8"); |
267 | | - let vers = stdout.split_whitespace().skip(1).next().unwrap(); |
268 | | - let is_nightly = option_env!("CARGO_TEST_DISABLE_NIGHTLY").is_none() |
269 | | - && (vers.contains("-nightly") || vers.contains("-dev")); |
270 | | - let minor = vers.split('.').skip(1).next().unwrap().parse().unwrap(); |
271 | | - unsafe { VERSION = (minor, is_nightly) } |
272 | | - }); |
273 | | - unsafe { VERSION } |
| 271 | + LazyLock::force(&VERSION).clone() |
274 | 272 | } |
275 | 273 |
|
276 | 274 | fn check_command(command_path: &Path, args: &[&str]) -> bool { |
|
0 commit comments