From 99c96c5bfe67ccbf7fc379458b8bcf9513bf9b7d Mon Sep 17 00:00:00 2001 From: marmeladema Date: Tue, 1 Sep 2020 21:49:36 +0100 Subject: [PATCH] driver: replace `lazy_static` by `SyncLazy` from std --- Cargo.lock | 1 - compiler/rustc_driver/Cargo.toml | 1 - compiler/rustc_driver/src/lib.rs | 12 +++++------- compiler/rustc_feature/src/builtin_attrs.rs | 17 +++++++++-------- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4a8855b4c5..f94d95d2dc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3439,7 +3439,6 @@ dependencies = [ name = "rustc_driver" version = "0.0.0" dependencies = [ - "lazy_static", "libc", "rustc_ast", "rustc_ast_pretty", diff --git a/compiler/rustc_driver/Cargo.toml b/compiler/rustc_driver/Cargo.toml index 76e8592254c..0d9dcb262b2 100644 --- a/compiler/rustc_driver/Cargo.toml +++ b/compiler/rustc_driver/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" crate-type = ["dylib"] [dependencies] -lazy_static = "1.0" libc = "0.2" tracing = { version = "0.1.18", features = ["release_max_level_info"] } tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] } diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 0d8332a20ae..c277e314d0e 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -11,8 +11,6 @@ #[macro_use] extern crate tracing; -#[macro_use] -extern crate lazy_static; pub extern crate rustc_plugin_impl as plugin; @@ -49,6 +47,7 @@ use std::env; use std::ffi::OsString; use std::fs; use std::io::{self, Read, Write}; +use std::lazy::SyncLazy; use std::mem; use std::panic::{self, catch_unwind}; use std::path::PathBuf; @@ -1142,13 +1141,12 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 { } } -lazy_static! { - static ref DEFAULT_HOOK: Box) + Sync + Send + 'static> = { +static DEFAULT_HOOK: SyncLazy) + Sync + Send + 'static>> = + SyncLazy::new(|| { let hook = panic::take_hook(); panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL))); hook - }; -} + }); /// Prints the ICE message, including backtrace and query stack. /// @@ -1223,7 +1221,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { /// /// A custom rustc driver can skip calling this to set up a custom ICE hook. pub fn install_ice_hook() { - lazy_static::initialize(&DEFAULT_HOOK); + SyncLazy::force(&DEFAULT_HOOK); } /// This allows tools to enable rust logging without having to magically match rustc's diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5d1b1bde84a..fc122db8ac1 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -590,12 +590,13 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool { BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() } -pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy> = SyncLazy::new(|| { - let mut map = FxHashMap::default(); - for attr in BUILTIN_ATTRIBUTES.iter() { - if map.insert(attr.0, attr).is_some() { - panic!("duplicate builtin attribute `{}`", attr.0); +pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy> = + SyncLazy::new(|| { + let mut map = FxHashMap::default(); + for attr in BUILTIN_ATTRIBUTES.iter() { + if map.insert(attr.0, attr).is_some() { + panic!("duplicate builtin attribute `{}`", attr.0); + } } - } - map -}); + map + });