Auto merge of #15542 - Veykril:std-once, r=Veykril

Less `once_cell` more `std`
This commit is contained in:
bors 2023-09-01 16:05:24 +00:00
commit ce650ce19d
7 changed files with 14 additions and 15 deletions

View File

@ -8,4 +8,4 @@ lint = "clippy --all-targets -- -Aclippy::collapsible_if -Aclippy::needless_pass
linker = "rust-lld" linker = "rust-lld"
[env] [env]
CARGO_WORKSPACE_DIR = { value = "", relative = true } CARGO_WORKSPACE_DIR = { value = "", relative = true }

1
Cargo.lock generated
View File

@ -854,7 +854,6 @@ version = "0.0.0"
dependencies = [ dependencies = [
"dashmap", "dashmap",
"hashbrown 0.12.3", "hashbrown 0.12.3",
"once_cell",
"rustc-hash", "rustc-hash",
"triomphe", "triomphe",
] ]

View File

@ -8,7 +8,8 @@
//! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to //! name resolution, and `BUILTIN_ATTRIBUTES` is almost entirely unchanged from the original, to
//! ease updating. //! ease updating.
use once_cell::sync::OnceCell; use std::sync::OnceLock;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
/// Ignored attribute namespaces used by tools. /// Ignored attribute namespaces used by tools.
@ -29,7 +30,7 @@ pub struct AttributeTemplate {
} }
pub fn find_builtin_attr_idx(name: &str) -> Option<usize> { pub fn find_builtin_attr_idx(name: &str) -> Option<usize> {
static BUILTIN_LOOKUP_TABLE: OnceCell<FxHashMap<&'static str, usize>> = OnceCell::new(); static BUILTIN_LOOKUP_TABLE: OnceLock<FxHashMap<&'static str, usize>> = OnceLock::new();
BUILTIN_LOOKUP_TABLE BUILTIN_LOOKUP_TABLE
.get_or_init(|| { .get_or_init(|| {
INERT_ATTRIBUTES.iter().map(|attr| attr.name).enumerate().map(|(a, b)| (b, a)).collect() INERT_ATTRIBUTES.iter().map(|attr| attr.name).enumerate().map(|(a, b)| (b, a)).collect()

View File

@ -1,10 +1,11 @@
//! Context for lowering paths. //! Context for lowering paths.
use std::cell::OnceCell;
use hir_expand::{ use hir_expand::{
ast_id_map::{AstIdMap, AstIdNode}, ast_id_map::{AstIdMap, AstIdNode},
hygiene::Hygiene, hygiene::Hygiene,
AstId, HirFileId, InFile, AstId, HirFileId, InFile,
}; };
use once_cell::unsync::OnceCell;
use syntax::ast; use syntax::ast;
use triomphe::Arc; use triomphe::Arc;

View File

@ -86,17 +86,16 @@ fn on_char_typed_inner(
if !stdx::always!(TRIGGER_CHARS.contains(char_typed)) { if !stdx::always!(TRIGGER_CHARS.contains(char_typed)) {
return None; return None;
} }
return match char_typed { let conv = |text_edit: Option<TextEdit>| {
Some(ExtendedTextEdit { edit: text_edit?, is_snippet: false })
};
match char_typed {
'.' => conv(on_dot_typed(&file.tree(), offset)), '.' => conv(on_dot_typed(&file.tree(), offset)),
'=' => conv(on_eq_typed(&file.tree(), offset)), '=' => conv(on_eq_typed(&file.tree(), offset)),
'<' => on_left_angle_typed(&file.tree(), offset), '<' => on_left_angle_typed(&file.tree(), offset),
'>' => conv(on_right_angle_typed(&file.tree(), offset)), '>' => conv(on_right_angle_typed(&file.tree(), offset)),
'{' => conv(on_opening_brace_typed(file, offset)), '{' => conv(on_opening_brace_typed(file, offset)),
_ => return None, _ => None,
};
fn conv(text_edit: Option<TextEdit>) -> Option<ExtendedTextEdit> {
Some(ExtendedTextEdit { edit: text_edit?, is_snippet: false })
} }
} }

View File

@ -16,6 +16,5 @@ doctest = false
# We need to freeze the version of the crate, as the raw-api feature is considered unstable # 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"] } dashmap = { version = "=5.4.0", features = ["raw-api"] }
hashbrown.workspace = true hashbrown.workspace = true
once_cell = "1.17.0"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
triomphe.workspace = true triomphe.workspace = true

View File

@ -6,11 +6,11 @@
fmt::{self, Debug, Display}, fmt::{self, Debug, Display},
hash::{BuildHasherDefault, Hash, Hasher}, hash::{BuildHasherDefault, Hash, Hasher},
ops::Deref, ops::Deref,
sync::OnceLock,
}; };
use dashmap::{DashMap, SharedValue}; use dashmap::{DashMap, SharedValue};
use hashbrown::{hash_map::RawEntryMut, HashMap}; use hashbrown::{hash_map::RawEntryMut, HashMap};
use once_cell::sync::OnceCell;
use rustc_hash::FxHasher; use rustc_hash::FxHasher;
use triomphe::Arc; use triomphe::Arc;
@ -177,12 +177,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
} }
pub struct InternStorage<T: ?Sized> { pub struct InternStorage<T: ?Sized> {
map: OnceCell<InternMap<T>>, map: OnceLock<InternMap<T>>,
} }
impl<T: ?Sized> InternStorage<T> { impl<T: ?Sized> InternStorage<T> {
pub const fn new() -> Self { pub const fn new() -> Self {
Self { map: OnceCell::new() } Self { map: OnceLock::new() }
} }
} }