Skip to content

Commit 2be5797

Browse files
authored
Rollup merge of rust-lang#98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
once cell renamings This PR does the renamings proposed in rust-lang#74465 (comment) - Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}` - Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}` (I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc) `@rustbot` label +T-libs-api -T-libs
2 parents 1dad353 + c1a2db3 commit 2be5797

File tree

40 files changed

+1250
-1215
lines changed

40 files changed

+1250
-1215
lines changed

compiler/rustc_codegen_cranelift/src/driver/jit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::Symbol;
1313

1414
use cranelift_jit::{JITBuilder, JITModule};
1515

16-
// FIXME use std::lazy::SyncOnceCell once it stabilizes
16+
// FIXME use std::sync::OnceLock once it stabilizes
1717
use once_cell::sync::OnceCell;
1818

1919
use crate::{prelude::*, BackendConfig};

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ use rustc_target::abi::Size;
3636

3737
use libc::c_uint;
3838
use smallvec::SmallVec;
39+
use std::cell::OnceCell;
3940
use std::cell::RefCell;
4041
use std::iter;
41-
use std::lazy::OnceCell;
4242
use tracing::debug;
4343

4444
mod create_scope_map;

compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ use regex::Regex;
3838
use tempfile::Builder as TempFileBuilder;
3939

4040
use std::borrow::Borrow;
41+
use std::cell::OnceCell;
4142
use std::collections::BTreeSet;
4243
use std::ffi::OsString;
4344
use std::fs::{File, OpenOptions};
4445
use std::io::{BufWriter, Write};
45-
use std::lazy::OnceCell;
4646
use std::ops::Deref;
4747
use std::path::{Path, PathBuf};
4848
use std::process::{ExitStatus, Output, Stdio};

compiler/rustc_data_structures/src/jobserver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pub use jobserver_crate::Client;
2-
use std::lazy::SyncLazy;
2+
use std::sync::LazyLock;
33

44
// We can only call `from_env` once per process
55

@@ -18,7 +18,7 @@ use std::lazy::SyncLazy;
1818
// Also note that we stick this in a global because there could be
1919
// multiple rustc instances in this process, and the jobserver is
2020
// per-process.
21-
static GLOBAL_CLIENT: SyncLazy<Client> = SyncLazy::new(|| unsafe {
21+
static GLOBAL_CLIENT: LazyLock<Client> = LazyLock::new(|| unsafe {
2222
Client::from_env().unwrap_or_else(|| {
2323
let client = Client::new(32).expect("failed to create jobserver");
2424
// Acquire a token for the main thread which we can release later

compiler/rustc_data_structures/src/sync.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ cfg_if! {
173173
pub use std::cell::RefMut as LockGuard;
174174
pub use std::cell::RefMut as MappedLockGuard;
175175

176-
pub use std::lazy::OnceCell;
176+
pub use std::cell::OnceCell;
177177

178178
use std::cell::RefCell as InnerRwLock;
179179
use std::cell::RefCell as InnerLock;
@@ -258,7 +258,7 @@ cfg_if! {
258258
pub use parking_lot::MutexGuard as LockGuard;
259259
pub use parking_lot::MappedMutexGuard as MappedLockGuard;
260260

261-
pub use std::lazy::SyncOnceCell as OnceCell;
261+
pub use std::sync::OnceLock as OnceCell;
262262

263263
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32, AtomicU64};
264264

compiler/rustc_driver/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ use std::env;
4747
use std::ffi::OsString;
4848
use std::fs;
4949
use std::io::{self, Read, Write};
50-
use std::lazy::SyncLazy;
5150
use std::panic::{self, catch_unwind};
5251
use std::path::PathBuf;
5352
use std::process::{self, Command, Stdio};
5453
use std::str;
54+
use std::sync::LazyLock;
5555
use std::time::Instant;
5656

5757
pub mod args;
@@ -1141,8 +1141,8 @@ pub fn catch_with_exit_code(f: impl FnOnce() -> interface::Result<()>) -> i32 {
11411141
}
11421142
}
11431143

1144-
static DEFAULT_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
1145-
SyncLazy::new(|| {
1144+
static DEFAULT_HOOK: LazyLock<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
1145+
LazyLock::new(|| {
11461146
let hook = panic::take_hook();
11471147
panic::set_hook(Box::new(|info| {
11481148
// Invoke the default handler, which prints the actual panic message and optionally a backtrace
@@ -1237,7 +1237,7 @@ pub fn install_ice_hook() {
12371237
if std::env::var("RUST_BACKTRACE").is_err() {
12381238
std::env::set_var("RUST_BACKTRACE", "full");
12391239
}
1240-
SyncLazy::force(&DEFAULT_HOOK);
1240+
LazyLock::force(&DEFAULT_HOOK);
12411241
}
12421242

12431243
/// This allows tools to enable rust logging without having to magically match rustc's

compiler/rustc_error_messages/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use std::path::{Path, PathBuf};
1818
use tracing::{instrument, trace};
1919

2020
#[cfg(not(parallel_compiler))]
21-
use std::lazy::Lazy;
21+
use std::cell::LazyCell as Lazy;
2222
#[cfg(parallel_compiler)]
23-
use std::lazy::SyncLazy as Lazy;
23+
use std::sync::LazyLock as Lazy;
2424

2525
#[cfg(parallel_compiler)]
2626
use intl_memoizer::concurrent::IntlLangMemoizer;

compiler/rustc_feature/src/builtin_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::{Features, Stability};
99
use rustc_data_structures::fx::FxHashMap;
1010
use rustc_span::symbol::{sym, Symbol};
1111

12-
use std::lazy::SyncLazy;
12+
use std::sync::LazyLock;
1313

1414
type GateFn = fn(&Features) -> bool;
1515

@@ -809,8 +809,8 @@ pub fn is_builtin_only_local(name: Symbol) -> bool {
809809
BUILTIN_ATTRIBUTE_MAP.get(&name).map_or(false, |attr| attr.only_local)
810810
}
811811

812-
pub static BUILTIN_ATTRIBUTE_MAP: SyncLazy<FxHashMap<Symbol, &BuiltinAttribute>> =
813-
SyncLazy::new(|| {
812+
pub static BUILTIN_ATTRIBUTE_MAP: LazyLock<FxHashMap<Symbol, &BuiltinAttribute>> =
813+
LazyLock::new(|| {
814814
let mut map = FxHashMap::default();
815815
for attr in BUILTIN_ATTRIBUTES.iter() {
816816
if map.insert(attr.name, attr).is_some() {

compiler/rustc_hir/src/lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_macros::HashStable_Generic;
1717
use rustc_span::symbol::{kw, sym, Symbol};
1818
use rustc_span::Span;
1919

20-
use std::lazy::SyncLazy;
20+
use std::sync::LazyLock;
2121

2222
pub enum LangItemGroup {
2323
Op,
@@ -134,7 +134,7 @@ macro_rules! language_item_table {
134134
}
135135

136136
/// A mapping from the name of the lang item to its order and the form it must be of.
137-
pub static ITEM_REFS: SyncLazy<FxHashMap<Symbol, (usize, Target)>> = SyncLazy::new(|| {
137+
pub static ITEM_REFS: LazyLock<FxHashMap<Symbol, (usize, Target)>> = LazyLock::new(|| {
138138
let mut item_refs = FxHashMap::default();
139139
$( item_refs.insert($module::$name, (LangItem::$variant as usize, $target)); )*
140140
item_refs

compiler/rustc_hir/src/weak_lang_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use rustc_ast as ast;
77
use rustc_data_structures::stable_map::StableMap;
88
use rustc_span::symbol::{sym, Symbol};
99

10-
use std::lazy::SyncLazy;
10+
use std::sync::LazyLock;
1111

1212
macro_rules! weak_lang_items {
1313
($($name:ident, $item:ident, $sym:ident;)*) => (
1414

15-
pub static WEAK_ITEMS_REFS: SyncLazy<StableMap<Symbol, LangItem>> = SyncLazy::new(|| {
15+
pub static WEAK_ITEMS_REFS: LazyLock<StableMap<Symbol, LangItem>> = LazyLock::new(|| {
1616
let mut map = StableMap::default();
1717
$(map.insert(sym::$name, LangItem::$item);)*
1818
map

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ use std::any::Any;
4444
use std::cell::RefCell;
4545
use std::ffi::OsString;
4646
use std::io::{self, BufWriter, Write};
47-
use std::lazy::SyncLazy;
4847
use std::marker::PhantomPinned;
4948
use std::path::{Path, PathBuf};
5049
use std::pin::Pin;
5150
use std::rc::Rc;
51+
use std::sync::LazyLock;
5252
use std::{env, fs, iter};
5353

5454
pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
@@ -774,7 +774,7 @@ pub fn prepare_outputs(
774774
Ok(outputs)
775775
}
776776

777-
pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
777+
pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
778778
let providers = &mut Providers::default();
779779
providers.analysis = analysis;
780780
proc_macro_decls::provide(providers);
@@ -799,7 +799,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy<Providers> = SyncLazy::new(|| {
799799
*providers
800800
});
801801

802-
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: SyncLazy<ExternProviders> = SyncLazy::new(|| {
802+
pub static DEFAULT_EXTERN_QUERY_PROVIDERS: LazyLock<ExternProviders> = LazyLock::new(|| {
803803
let mut extern_providers = ExternProviders::default();
804804
rustc_metadata::provide_extern(&mut extern_providers);
805805
rustc_codegen_ssa::provide_extern(&mut extern_providers);

compiler/rustc_interface/src/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ use rustc_span::source_map::FileLoader;
2424
use rustc_span::symbol::{sym, Symbol};
2525
use std::env;
2626
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
27-
use std::lazy::SyncOnceCell;
2827
use std::mem;
2928
#[cfg(not(parallel_compiler))]
3029
use std::panic;
3130
use std::path::{Path, PathBuf};
3231
use std::sync::atomic::{AtomicBool, Ordering};
32+
use std::sync::OnceLock;
3333
use std::thread;
3434
use tracing::info;
3535

@@ -242,7 +242,7 @@ pub fn get_codegen_backend(
242242
maybe_sysroot: &Option<PathBuf>,
243243
backend_name: Option<&str>,
244244
) -> Box<dyn CodegenBackend> {
245-
static LOAD: SyncOnceCell<unsafe fn() -> Box<dyn CodegenBackend>> = SyncOnceCell::new();
245+
static LOAD: OnceLock<unsafe fn() -> Box<dyn CodegenBackend>> = OnceLock::new();
246246

247247
let load = LOAD.get_or_init(|| {
248248
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
@@ -265,7 +265,7 @@ pub fn get_codegen_backend(
265265
// loading, so we leave the code here. It is potentially useful for other tools
266266
// that want to invoke the rustc binary while linking to rustc as well.
267267
pub fn rustc_path<'a>() -> Option<&'a Path> {
268-
static RUSTC_PATH: SyncOnceCell<Option<PathBuf>> = SyncOnceCell::new();
268+
static RUSTC_PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
269269

270270
const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");
271271

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A helpful diagram for debugging dataflow problems.
22
33
use std::borrow::Cow;
4-
use std::lazy::SyncOnceCell;
4+
use std::sync::OnceLock;
55
use std::{io, ops, str};
66

77
use regex::Regex;
@@ -590,7 +590,7 @@ where
590590

591591
macro_rules! regex {
592592
($re:literal $(,)?) => {{
593-
static RE: SyncOnceCell<regex::Regex> = SyncOnceCell::new();
593+
static RE: OnceLock<regex::Regex> = OnceLock::new();
594594
RE.get_or_init(|| Regex::new($re).unwrap())
595595
}};
596596
}

compiler/rustc_mir_transform/src/coverage/debug.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ use rustc_middle::ty::TyCtxt;
123123
use rustc_span::Span;
124124

125125
use std::iter;
126-
use std::lazy::SyncOnceCell;
127126
use std::ops::Deref;
127+
use std::sync::OnceLock;
128128

129129
pub const NESTED_INDENT: &str = " ";
130130

131131
const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS";
132132

133133
pub(super) fn debug_options<'a>() -> &'a DebugOptions {
134-
static DEBUG_OPTIONS: SyncOnceCell<DebugOptions> = SyncOnceCell::new();
134+
static DEBUG_OPTIONS: OnceLock<DebugOptions> = OnceLock::new();
135135

136136
&DEBUG_OPTIONS.get_or_init(DebugOptions::from_env)
137137
}

compiler/rustc_typeck/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use rustc_span::{Span, DUMMY_SP};
2929
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
3030
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCauseCode, WellFormedLoc};
3131

32+
use std::cell::LazyCell;
3233
use std::convert::TryInto;
3334
use std::iter;
34-
use std::lazy::Lazy;
3535
use std::ops::ControlFlow;
3636

3737
/// Helper type of a temporary returned by `.for_item(...)`.
@@ -1728,7 +1728,7 @@ fn check_variances_for_type_defn<'tcx>(
17281728
identify_constrained_generic_params(tcx, ty_predicates, None, &mut constrained_parameters);
17291729

17301730
// Lazily calculated because it is only needed in case of an error.
1731-
let explicitly_bounded_params = Lazy::new(|| {
1731+
let explicitly_bounded_params = LazyCell::new(|| {
17321732
let icx = crate::collect::ItemCtxt::new(tcx, item.def_id.to_def_id());
17331733
hir_generics
17341734
.predicates

library/core/src/cell.rs

+8
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ use crate::mem;
199199
use crate::ops::{CoerceUnsized, Deref, DerefMut};
200200
use crate::ptr::{self, NonNull};
201201

202+
mod lazy;
203+
mod once;
204+
205+
#[unstable(feature = "once_cell", issue = "74465")]
206+
pub use lazy::LazyCell;
207+
#[unstable(feature = "once_cell", issue = "74465")]
208+
pub use once::OnceCell;
209+
202210
/// A mutable memory location.
203211
///
204212
/// # Examples

0 commit comments

Comments
 (0)