From 67b8f9491c30cba0e4892f6b5b8bda8b312428da Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 1 Sep 2020 21:31:22 +0100 Subject: [PATCH] hir: replace `lazy_static` by `SyncLazy` from std --- Cargo.lock | 1 - compiler/rustc_hir/Cargo.toml | 1 - compiler/rustc_hir/src/lang_items.rs | 16 +++++++--------- compiler/rustc_hir/src/lib.rs | 1 + compiler/rustc_hir/src/weak_lang_items.rs | 14 ++++++-------- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c710bf164a8..3cc5aec6cac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3530,7 +3530,6 @@ version = "0.0.0" name = "rustc_hir" version = "0.0.0" dependencies = [ - "lazy_static", "rustc_ast", "rustc_data_structures", "rustc_index", diff --git a/compiler/rustc_hir/Cargo.toml b/compiler/rustc_hir/Cargo.toml index ed295ff0058..b24c208c76a 100644 --- a/compiler/rustc_hir/Cargo.toml +++ b/compiler/rustc_hir/Cargo.toml @@ -15,6 +15,5 @@ rustc_index = { path = "../rustc_index" } rustc_span = { path = "../rustc_span" } rustc_serialize = { path = "../rustc_serialize" } rustc_ast = { path = "../rustc_ast" } -lazy_static = "1" tracing = "0.1" smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index acf6847c014..5e4c03bec83 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -17,7 +17,7 @@ use rustc_macros::HashStable_Generic; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::Span; -use lazy_static::lazy_static; +use std::lazy::SyncLazy; pub enum LangItemGroup { Op, @@ -117,14 +117,12 @@ macro_rules! language_item_table { )* } - lazy_static! { - /// A mapping from the name of the lang item to its order and the form it must be of. - pub static ref ITEM_REFS: FxHashMap = { - let mut item_refs = FxHashMap::default(); - $( item_refs.insert($name, (LangItem::$variant as usize, $target)); )* - item_refs - }; - } + /// A mapping from the name of the lang item to its order and the form it must be of. + pub static ITEM_REFS: SyncLazy> = SyncLazy::new(|| { + let mut item_refs = FxHashMap::default(); + $( item_refs.insert($name, (LangItem::$variant as usize, $target)); )* + item_refs + }); // End of the macro } diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index 19ea1de5683..c69a9b063ae 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -6,6 +6,7 @@ #![feature(const_fn)] // For the unsizing cast on `&[]` #![feature(const_panic)] #![feature(in_band_lifetimes)] +#![feature(once_cell)] #![feature(or_patterns)] #![recursion_limit = "256"] diff --git a/compiler/rustc_hir/src/weak_lang_items.rs b/compiler/rustc_hir/src/weak_lang_items.rs index 129eec7d29e..52f28bf8f4c 100644 --- a/compiler/rustc_hir/src/weak_lang_items.rs +++ b/compiler/rustc_hir/src/weak_lang_items.rs @@ -7,18 +7,16 @@ use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_span::symbol::{sym, Symbol}; -use lazy_static::lazy_static; +use std::lazy::SyncLazy; macro_rules! weak_lang_items { ($($name:ident, $item:ident, $sym:ident;)*) => ( -lazy_static! { - pub static ref WEAK_ITEMS_REFS: FxHashMap = { - let mut map = FxHashMap::default(); - $(map.insert(sym::$name, LangItem::$item);)* - map - }; -} +pub static WEAK_ITEMS_REFS: SyncLazy> = SyncLazy::new(|| { + let mut map = FxHashMap::default(); + $(map.insert(sym::$name, LangItem::$item);)* + map +}); /// The `check_name` argument avoids the need for `librustc_hir` to depend on /// `librustc_session`.