driver: replace lazy_static by SyncLazy from std

This commit is contained in:
marmeladema 2020-09-01 21:49:36 +01:00
parent 73a7204983
commit 99c96c5bfe
4 changed files with 14 additions and 17 deletions

View File

@ -3439,7 +3439,6 @@ dependencies = [
name = "rustc_driver" name = "rustc_driver"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"lazy_static",
"libc", "libc",
"rustc_ast", "rustc_ast",
"rustc_ast_pretty", "rustc_ast_pretty",

View File

@ -8,7 +8,6 @@ edition = "2018"
crate-type = ["dylib"] crate-type = ["dylib"]
[dependencies] [dependencies]
lazy_static = "1.0"
libc = "0.2" libc = "0.2"
tracing = { version = "0.1.18", features = ["release_max_level_info"] } 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"] } tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }

View File

@ -11,8 +11,6 @@
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;
#[macro_use]
extern crate lazy_static;
pub extern crate rustc_plugin_impl as plugin; pub extern crate rustc_plugin_impl as plugin;
@ -49,6 +47,7 @@
use std::ffi::OsString; use std::ffi::OsString;
use std::fs; use std::fs;
use std::io::{self, Read, Write}; use std::io::{self, Read, Write};
use std::lazy::SyncLazy;
use std::mem; use std::mem;
use std::panic::{self, catch_unwind}; use std::panic::{self, catch_unwind};
use std::path::PathBuf; use std::path::PathBuf;
@ -1142,13 +1141,12 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
} }
} }
lazy_static! { static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
static ref DEFAULT_HOOK: Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static> = { SyncLazy::new(|| {
let hook = panic::take_hook(); let hook = panic::take_hook();
panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL))); panic::set_hook(Box::new(|info| report_ice(info, BUG_REPORT_URL)));
hook hook
}; });
}
/// Prints the ICE message, including backtrace and query stack. /// 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. /// A custom rustc driver can skip calling this to set up a custom ICE hook.
pub fn install_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 /// This allows tools to enable rust logging without having to magically match rustc's

View File

@ -590,12 +590,13 @@ pub fn is_builtin_attr_name(name: Symbol) -> bool {
BUILTIN_ATTRIBUTE_MAP.get(&name).is_some() BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
} }
pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &'static BuiltinAttribute>> = SyncLazy::new(|| { pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &'static BuiltinAttribute>> =
let mut map = FxHashMap::default(); SyncLazy::new(|| {
for attr in BUILTIN_ATTRIBUTES.iter() { let mut map = FxHashMap::default();
if map.insert(attr.0, attr).is_some() { for attr in BUILTIN_ATTRIBUTES.iter() {
panic!("duplicate builtin attribute `{}`", attr.0); if map.insert(attr.0, attr).is_some() {
panic!("duplicate builtin attribute `{}`", attr.0);
}
} }
} map
map });
});