Skip to content

Commit

Permalink
Replace lazy_static! macro with once_cell
Browse files Browse the repository at this point in the history
lazy_static! has fallen out of favor since better, non-macro ways of
accomplishing lazy init have been found.

rust-lang-nursery/lazy-static.rs#111
  • Loading branch information
dralley committed Jan 27, 2020
1 parent d7085db commit 67f93c4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
10 changes: 8 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ proc-macro2 = "1.0"
rustpython-compiler = { path = "../compiler", version = "0.1.1" }
rustpython-bytecode = { path = "../bytecode", version = "0.1.1" }
maplit = "1.0"
lazy_static = "1"
once_cell = "1.3.1"
9 changes: 4 additions & 5 deletions derive/src/compile_bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ use std::fs;
use std::path::{Path, PathBuf};
use syn::parse::{Parse, ParseStream, Result as ParseResult};
use syn::{self, parse2, Lit, LitByteStr, LitStr, Meta, Token};
use once_cell::sync::Lazy;

lazy_static::lazy_static! {
static ref CARGO_MANIFEST_DIR: PathBuf = PathBuf::from(
env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"),
);
}
static CARGO_MANIFEST_DIR: Lazy<PathBuf> = Lazy::new(|| {
PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR is not present"))
});

enum CompilationSourceKind {
File(PathBuf),
Expand Down
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rustc_version_runtime = "0.1.*"
statrs = "0.12.0"
caseless = "0.2.1"
chrono = { version = "=0.4.9", features = ["wasmbind"] }
lazy_static = "^1.0.1"
once_cell = "1.3.1"
lexical = "4"
itertools = "0.8"
hex = "0.4.0"
Expand Down
2 changes: 0 additions & 2 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ extern crate flamer;

#[macro_use]
extern crate bitflags;
#[macro_use]
extern crate lazy_static;
extern crate lexical;
#[macro_use]
extern crate log;
Expand Down
5 changes: 2 additions & 3 deletions vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::sync::{Mutex, MutexGuard};
use arr_macro::arr;
use num_bigint::BigInt;
use num_traits::ToPrimitive;
use once_cell::sync::Lazy;
#[cfg(feature = "rustpython-compiler")]
use rustpython_compiler::{compile, error::CompileError};

Expand Down Expand Up @@ -1322,9 +1323,7 @@ impl Default for VirtualMachine {
}
}

lazy_static! {
static ref REPR_GUARDS: Mutex<HashSet<usize>> = { Mutex::new(HashSet::new()) };
}
static REPR_GUARDS: Lazy<Mutex<HashSet<usize>>> = Lazy::new(|| Mutex::new(HashSet::new()));

pub struct ReprGuard {
id: usize,
Expand Down

0 comments on commit 67f93c4

Please sign in to comment.