From c09f175d599e74f86d59e4ffabbd256356d7d227 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 1 Sep 2023 17:30:59 +0200 Subject: [PATCH] Less `once_cell` more `std` --- .cargo/config.toml | 2 +- Cargo.lock | 1 - crates/hir-def/src/attr/builtin.rs | 5 +++-- crates/hir-def/src/lower.rs | 3 ++- crates/ide/src/typing.rs | 11 +++++------ crates/intern/Cargo.toml | 1 - crates/intern/src/lib.rs | 6 +++--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index 24745d1c806..c9ad7803951 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -8,4 +8,4 @@ lint = "clippy --all-targets -- -Aclippy::collapsible_if -Aclippy::needless_pass linker = "rust-lld" [env] -CARGO_WORKSPACE_DIR = { value = "", relative = true } \ No newline at end of file +CARGO_WORKSPACE_DIR = { value = "", relative = true } diff --git a/Cargo.lock b/Cargo.lock index cf364d28de0..f6900f883a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -854,7 +854,6 @@ version = "0.0.0" dependencies = [ "dashmap", "hashbrown 0.12.3", - "once_cell", "rustc-hash", "triomphe", ] diff --git a/crates/hir-def/src/attr/builtin.rs b/crates/hir-def/src/attr/builtin.rs index cead64a3374..565e48ccd33 100644 --- a/crates/hir-def/src/attr/builtin.rs +++ b/crates/hir-def/src/attr/builtin.rs @@ -8,7 +8,8 @@ //! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to //! ease updating. -use once_cell::sync::OnceCell; +use std::sync::OnceLock; + use rustc_hash::FxHashMap; /// Ignored attribute namespaces used by tools. @@ -29,7 +30,7 @@ pub struct AttributeTemplate { } pub fn find_builtin_attr_idx(name: &str) -> Option { - static BUILTIN_LOOKUP_TABLE: OnceCell> = OnceCell::new(); + static BUILTIN_LOOKUP_TABLE: OnceLock> = OnceLock::new(); BUILTIN_LOOKUP_TABLE .get_or_init(|| { INERT_ATTRIBUTES.iter().map(|attr| attr.name).enumerate().map(|(a, b)| (b, a)).collect() diff --git a/crates/hir-def/src/lower.rs b/crates/hir-def/src/lower.rs index e523c229179..52781d98892 100644 --- a/crates/hir-def/src/lower.rs +++ b/crates/hir-def/src/lower.rs @@ -1,10 +1,11 @@ //! Context for lowering paths. +use std::cell::OnceCell; + use hir_expand::{ ast_id_map::{AstIdMap, AstIdNode}, hygiene::Hygiene, AstId, HirFileId, InFile, }; -use once_cell::unsync::OnceCell; use syntax::ast; use triomphe::Arc; diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index c7e403f6b1a..27dedab13ea 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs @@ -86,17 +86,16 @@ fn on_char_typed_inner( if !stdx::always!(TRIGGER_CHARS.contains(char_typed)) { return None; } - return match char_typed { + let conv = |text_edit: Option| { + Some(ExtendedTextEdit { edit: text_edit?, is_snippet: false }) + }; + match char_typed { '.' => conv(on_dot_typed(&file.tree(), offset)), '=' => conv(on_eq_typed(&file.tree(), offset)), '<' => on_left_angle_typed(&file.tree(), offset), '>' => conv(on_right_angle_typed(&file.tree(), offset)), '{' => conv(on_opening_brace_typed(file, offset)), - _ => return None, - }; - - fn conv(text_edit: Option) -> Option { - Some(ExtendedTextEdit { edit: text_edit?, is_snippet: false }) + _ => None, } } diff --git a/crates/intern/Cargo.toml b/crates/intern/Cargo.toml index 4d56c771960..89b302c796b 100644 --- a/crates/intern/Cargo.toml +++ b/crates/intern/Cargo.toml @@ -16,6 +16,5 @@ doctest = false # We need to freeze the version of the crate, as the raw-api feature is considered unstable dashmap = { version = "=5.4.0", features = ["raw-api"] } hashbrown.workspace = true -once_cell = "1.17.0" rustc-hash = "1.1.0" triomphe.workspace = true diff --git a/crates/intern/src/lib.rs b/crates/intern/src/lib.rs index dabbf3a38b5..2934d26674d 100644 --- a/crates/intern/src/lib.rs +++ b/crates/intern/src/lib.rs @@ -6,11 +6,11 @@ use std::{ fmt::{self, Debug, Display}, hash::{BuildHasherDefault, Hash, Hasher}, ops::Deref, + sync::OnceLock, }; use dashmap::{DashMap, SharedValue}; use hashbrown::{hash_map::RawEntryMut, HashMap}; -use once_cell::sync::OnceCell; use rustc_hash::FxHasher; use triomphe::Arc; @@ -177,12 +177,12 @@ impl Display for Interned { } pub struct InternStorage { - map: OnceCell>, + map: OnceLock>, } impl InternStorage { pub const fn new() -> Self { - Self { map: OnceCell::new() } + Self { map: OnceLock::new() } } }