Auto merge of #76216 - marmeladema:use-once-cell-from-std, r=matklad

compiler: use `OnceCell` from std

Fixes #76192

The only remaining direct use of `lazy_static` crate is in `src/bootstrap`  but I am not sure how I can remove that dependency for now.

r? @matklad
This commit is contained in:
bors 2020-09-02 06:46:21 +00:00
commit da897dfb6d
15 changed files with 56 additions and 71 deletions

View file

@ -2,7 +2,6 @@ use crate::interface::{Compiler, Result};
use crate::proc_macro_decls;
use crate::util;
use once_cell::sync::Lazy;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::{self as ast, visit};
use rustc_codegen_ssa::back::link::emit_metadata;
@ -46,6 +45,7 @@ use std::any::Any;
use std::cell::RefCell;
use std::ffi::OsString;
use std::io::{self, BufWriter, Write};
use std::lazy::SyncLazy;
use std::path::PathBuf;
use std::rc::Rc;
use std::{env, fs, iter, mem};
@ -681,7 +681,7 @@ pub fn prepare_outputs(
Ok(outputs)
}
pub static DEFAULT_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
let providers = &mut Providers::default();
providers.analysis = analysis;
proc_macro_decls::provide(providers);
@ -704,7 +704,7 @@ pub static DEFAULT_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
*providers
});
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: Lazy<Providers> = Lazy::new(|| {
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
let mut extern_providers = *DEFAULT_QUERY_PROVIDERS;
rustc_metadata::provide_extern(&mut extern_providers);
rustc_codegen_ssa::provide_extern(&mut extern_providers);

View file

@ -25,6 +25,7 @@ use rustc_span::symbol::{sym, Symbol};
use smallvec::SmallVec;
use std::env;
use std::io::{self, Write};
use std::lazy::SyncOnceCell;
use std::mem;
use std::ops::DerefMut;
use std::path::{Path, PathBuf};
@ -243,8 +244,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
// loading, so we leave the code here. It is potentially useful for other tools
// that want to invoke the rustc binary while linking to rustc as well.
pub fn rustc_path<'a>() -> Option<&'a Path> {
static RUSTC_PATH: once_cell::sync::OnceCell<Option<PathBuf>> =
once_cell::sync::OnceCell::new();
static RUSTC_PATH: SyncOnceCell<Option<PathBuf>> = SyncOnceCell::new();
const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");