Skip to content

Commit 12273cb

Browse files
committed
Make init_locking return a reference to the initialized data
1 parent a6ac22e commit 12273cb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/librustc_data_structures/sync.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,15 @@ impl<T> Once<T> {
497497
/// If the value was already initialized the closure is not called and `false` is returned,
498498
/// otherwise if the value from the closure initializes the inner value, `true` is returned
499499
#[inline]
500-
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> bool {
501-
let mut lock = self.0.lock();
502-
if lock.is_some() {
503-
return false;
500+
pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T {
501+
{
502+
let mut lock = self.0.lock();
503+
if lock.is_none() {
504+
*lock = Some(f());
505+
}
504506
}
505-
*lock = Some(f());
506-
true
507+
508+
self.borrow()
507509
}
508510

509511
/// Tries to initialize the inner value by calling the closure without ensuring that no-one

src/librustc_metadata/decoder.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,7 @@ impl<'a, 'tcx> CrateMetadata {
13511351
translated_source_file: local_version,
13521352
}
13531353
}).collect()
1354-
});
1355-
1356-
self.source_map_import_info.borrow()
1354+
})
13571355
}
13581356

13591357
/// Get the `DepNodeIndex` corresponding this crate. The result of this

0 commit comments

Comments
 (0)