Skip to content

Commit f3d072e

Browse files
committed
Update once_cell closure-taking function names
- 'get_or_init' -> 'get_or_init_with' - 'get_or_try_init' -> 'get_or_try_init_with'
1 parent acd27bb commit f3d072e

File tree

23 files changed

+61
-58
lines changed

23 files changed

+61
-58
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
22822282
}
22832283

22842284
fn dominators(&self) -> &Dominators<BasicBlock> {
2285-
self.dominators.get_or_init(|| self.body.basic_blocks.dominators())
2285+
self.dominators.get_or_init_with(|| self.body.basic_blocks.dominators())
22862286
}
22872287
}
22882288

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
492492

493493
// FIXME(mw): Cache this via a regular UniqueTypeId instead of an extra field in the debug context.
494494
fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll DIType {
495-
*debug_context(cx).recursion_marker_type.get_or_init(move || {
495+
*debug_context(cx).recursion_marker_type.get_or_init_with(move || {
496496
unsafe {
497497
// The choice of type here is pretty arbitrary -
498498
// anything reading the debuginfo for a recursive

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ fn add_native_libs_from_crate(
23182318
cmd.link_whole_staticlib(
23192319
name,
23202320
verbatim,
2321-
&search_paths.get_or_init(|| archive_search_paths(sess)),
2321+
&search_paths.get_or_init_with(|| archive_search_paths(sess)),
23222322
);
23232323
} else {
23242324
cmd.link_staticlib(name, verbatim)

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,12 @@ pub fn create_global_ctxt<'tcx>(
693693
callback(sess, &mut local_providers, &mut extern_providers);
694694
}
695695

696-
let queries = queries.get_or_init(|| {
696+
let queries = queries.get_or_init_with(|| {
697697
TcxQueries::new(local_providers, extern_providers, query_result_on_disk_cache)
698698
});
699699

700700
sess.time("setup_global_ctxt", || {
701-
gcx_cell.get_or_init(move || {
701+
gcx_cell.get_or_init_with(move || {
702702
TyCtxt::create_global_ctxt(
703703
sess,
704704
lint_store,

compiler/rustc_interface/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ pub fn get_codegen_backend(
239239
) -> Box<dyn CodegenBackend> {
240240
static LOAD: OnceLock<unsafe fn() -> Box<dyn CodegenBackend>> = OnceLock::new();
241241

242-
let load = LOAD.get_or_init(|| {
242+
let load = LOAD.get_or_init_with(|| {
243243
let default_codegen_backend = option_env!("CFG_DEFAULT_CODEGEN_BACKEND").unwrap_or("llvm");
244244

245245
match backend_name.unwrap_or(default_codegen_backend) {
@@ -264,7 +264,7 @@ pub fn rustc_path<'a>() -> Option<&'a Path> {
264264

265265
const BIN_PATH: &str = env!("RUSTC_INSTALL_BINDIR");
266266

267-
RUSTC_PATH.get_or_init(|| get_rustc_path_inner(BIN_PATH)).as_deref()
267+
RUSTC_PATH.get_or_init_with(|| get_rustc_path_inner(BIN_PATH)).as_deref()
268268
}
269269

270270
fn get_rustc_path_inner(bin_path: &str) -> Option<PathBuf> {

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
12971297
// Slow path: We need to find out the new `DefIndex` of the provided
12981298
// `DefPathHash`, if its still exists. This requires decoding every `DefPathHash`
12991299
// stored in this crate.
1300-
let map = self.cdata.expn_hash_map.get_or_init(|| {
1300+
let map = self.cdata.expn_hash_map.get_or_init_with(|| {
13011301
let end_id = self.root.expn_hashes.size() as u32;
13021302
let mut map =
13031303
UnhashMap::with_capacity_and_hasher(end_id as usize, Default::default());

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> BasicBlocks<'tcx> {
3838
/// Returns true if control-flow graph contains a cycle reachable from the `START_BLOCK`.
3939
#[inline]
4040
pub fn is_cfg_cyclic(&self) -> bool {
41-
*self.cache.is_cyclic.get_or_init(|| graph::is_cyclic(self))
41+
*self.cache.is_cyclic.get_or_init_with(|| graph::is_cyclic(self))
4242
}
4343

4444
pub fn dominators(&self) -> Dominators<BasicBlock> {
@@ -48,7 +48,7 @@ impl<'tcx> BasicBlocks<'tcx> {
4848
/// Returns predecessors for each basic block.
4949
#[inline]
5050
pub fn predecessors(&self) -> &Predecessors {
51-
self.cache.predecessors.get_or_init(|| {
51+
self.cache.predecessors.get_or_init_with(|| {
5252
let mut preds = IndexVec::from_elem(SmallVec::new(), &self.basic_blocks);
5353
for (bb, data) in self.basic_blocks.iter_enumerated() {
5454
if let Some(term) = &data.terminator {
@@ -64,7 +64,7 @@ impl<'tcx> BasicBlocks<'tcx> {
6464
/// Returns basic blocks in a postorder.
6565
#[inline]
6666
pub fn postorder(&self) -> &[BasicBlock] {
67-
self.cache.postorder.get_or_init(|| {
67+
self.cache.postorder.get_or_init_with(|| {
6868
Postorder::new(&self.basic_blocks, START_BLOCK).map(|(bb, _)| bb).collect()
6969
})
7070
}
@@ -73,7 +73,7 @@ impl<'tcx> BasicBlocks<'tcx> {
7373
/// values that lead to a `target` block from a `switch` block.
7474
#[inline]
7575
pub fn switch_sources(&self) -> &SwitchSources {
76-
self.cache.switch_sources.get_or_init(|| {
76+
self.cache.switch_sources.get_or_init_with(|| {
7777
let mut switch_sources: SwitchSources = FxHashMap::default();
7878
for (bb, data) in self.basic_blocks.iter_enumerated() {
7979
if let Some(Terminator {

compiler/rustc_mir_dataflow/src/framework/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ where
594594
macro_rules! regex {
595595
($re:literal $(,)?) => {{
596596
static RE: OnceLock<regex::Regex> = OnceLock::new();
597-
RE.get_or_init(|| Regex::new($re).unwrap())
597+
RE.get_or_init_with(|| Regex::new($re).unwrap())
598598
}};
599599
}
600600

compiler/rustc_mir_transform/src/coverage/debug.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const RUSTC_COVERAGE_DEBUG_OPTIONS: &str = "RUSTC_COVERAGE_DEBUG_OPTIONS";
133133
pub(super) fn debug_options<'a>() -> &'a DebugOptions {
134134
static DEBUG_OPTIONS: OnceLock<DebugOptions> = OnceLock::new();
135135

136-
&DEBUG_OPTIONS.get_or_init(DebugOptions::from_env)
136+
&DEBUG_OPTIONS.get_or_init_with(DebugOptions::from_env)
137137
}
138138

139139
/// Parses and maintains coverage-specific debug options captured from the environment variable

library/core/src/cell/lazy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<T, F: FnOnce() -> T> LazyCell<T, F> {
7777
#[inline]
7878
#[unstable(feature = "once_cell", issue = "74465")]
7979
pub fn force(this: &LazyCell<T, F>) -> &T {
80-
this.cell.get_or_init(|| match this.init.take() {
80+
this.cell.get_or_init_with(|| match this.init.take() {
8181
Some(f) => f(),
8282
None => panic!("`Lazy` instance has previously been poisoned"),
8383
})

0 commit comments

Comments
 (0)