diff options
-rw-r--r-- | Cargo.lock | 5 | ||||
-rw-r--r-- | crates/hir_ty/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/hir_ty/src/tests.rs | 7 | ||||
-rw-r--r-- | crates/stdx/src/lib.rs | 30 |
4 files changed, 9 insertions, 34 deletions
diff --git a/Cargo.lock b/Cargo.lock index 1a4a63550..1ae6bed65 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -612,6 +612,7 @@ dependencies = [ | |||
612 | "hir_expand", | 612 | "hir_expand", |
613 | "itertools", | 613 | "itertools", |
614 | "log", | 614 | "log", |
615 | "once_cell", | ||
615 | "profile", | 616 | "profile", |
616 | "rustc-hash", | 617 | "rustc-hash", |
617 | "scoped-tls", | 618 | "scoped-tls", |
@@ -1053,9 +1054,9 @@ checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" | |||
1053 | 1054 | ||
1054 | [[package]] | 1055 | [[package]] |
1055 | name = "once_cell" | 1056 | name = "once_cell" |
1056 | version = "1.4.1" | 1057 | version = "1.5.0" |
1057 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1058 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1058 | checksum = "260e51e7efe62b592207e9e13a68e43692a7a279171d6ba57abd208bf23645ad" | 1059 | checksum = "95c43eba5c640051fbde86a3377842386a94281df3ff0a5f0365c2075ed5c66f" |
1059 | 1060 | ||
1060 | [[package]] | 1061 | [[package]] |
1061 | name = "oorandom" | 1062 | name = "oorandom" |
diff --git a/crates/hir_ty/Cargo.toml b/crates/hir_ty/Cargo.toml index fdc65a5c3..cf5c38a23 100644 --- a/crates/hir_ty/Cargo.toml +++ b/crates/hir_ty/Cargo.toml | |||
@@ -35,3 +35,4 @@ expect-test = "1.0" | |||
35 | tracing = "0.1" | 35 | tracing = "0.1" |
36 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } | 36 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } |
37 | tracing-tree = { version = "0.1.4" } | 37 | tracing-tree = { version = "0.1.4" } |
38 | once_cell = { version = "1.5.0", features = ["unstable"] } | ||
diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index 104ef334c..0a400cb70 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs | |||
@@ -22,7 +22,8 @@ use hir_def::{ | |||
22 | AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, | 22 | AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId, |
23 | }; | 23 | }; |
24 | use hir_expand::{db::AstDatabase, InFile}; | 24 | use hir_expand::{db::AstDatabase, InFile}; |
25 | use stdx::{format_to, RacyFlag}; | 25 | use once_cell::race::OnceBool; |
26 | use stdx::format_to; | ||
26 | use syntax::{ | 27 | use syntax::{ |
27 | algo, | 28 | algo, |
28 | ast::{self, AstNode}, | 29 | ast::{self, AstNode}, |
@@ -40,8 +41,8 @@ use crate::{ | |||
40 | // `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots. | 41 | // `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots. |
41 | 42 | ||
42 | fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> { | 43 | fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> { |
43 | static ENABLE: RacyFlag = RacyFlag::new(); | 44 | static ENABLE: OnceBool = OnceBool::new(); |
44 | if !ENABLE.get(|| env::var("CHALK_DEBUG").is_ok()) { | 45 | if !ENABLE.get_or_init(|| env::var("CHALK_DEBUG").is_ok()) { |
45 | return None; | 46 | return None; |
46 | } | 47 | } |
47 | 48 | ||
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 59d89f47d..374ed5910 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -1,8 +1,5 @@ | |||
1 | //! Missing batteries for standard libraries. | 1 | //! Missing batteries for standard libraries. |
2 | use std::{ | 2 | use std::time::Instant; |
3 | sync::atomic::{AtomicUsize, Ordering}, | ||
4 | time::Instant, | ||
5 | }; | ||
6 | 3 | ||
7 | mod macros; | 4 | mod macros; |
8 | pub mod panic_context; | 5 | pub mod panic_context; |
@@ -150,31 +147,6 @@ where | |||
150 | left | 147 | left |
151 | } | 148 | } |
152 | 149 | ||
153 | pub struct RacyFlag(AtomicUsize); | ||
154 | |||
155 | impl RacyFlag { | ||
156 | pub const fn new() -> RacyFlag { | ||
157 | RacyFlag(AtomicUsize::new(!0)) | ||
158 | } | ||
159 | |||
160 | pub fn get(&self, init: impl FnMut() -> bool) -> bool { | ||
161 | let mut init = Some(init); | ||
162 | self.get_impl(&mut || init.take().map_or(false, |mut f| f())) | ||
163 | } | ||
164 | |||
165 | fn get_impl(&self, init: &mut dyn FnMut() -> bool) -> bool { | ||
166 | match self.0.load(Ordering::Relaxed) { | ||
167 | 0 => false, | ||
168 | 1 => true, | ||
169 | _ => { | ||
170 | let res = init(); | ||
171 | self.0.store(if res { 1 } else { 0 }, Ordering::Relaxed); | ||
172 | res | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | #[cfg(test)] | 150 | #[cfg(test)] |
179 | mod tests { | 151 | mod tests { |
180 | use super::*; | 152 | use super::*; |