diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2019-10-30 18:08:53 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2019-10-30 18:35:54 -0300 |
| commit | 12273cb7f66f463683ad4d6c54b17afe0b7d8422 (patch) | |
| tree | 5a2f502cefbbabf44bbd4eb6f85597bc91357412 | |
| parent | a6ac22e7e880914826b7b036bcfc6e748a78904d (diff) | |
| download | rust-12273cb7f66f463683ad4d6c54b17afe0b7d8422.tar.gz rust-12273cb7f66f463683ad4d6c54b17afe0b7d8422.zip | |
Make init_locking return a reference to the initialized data
| -rw-r--r-- | src/librustc_data_structures/sync.rs | 14 | ||||
| -rw-r--r-- | src/librustc_metadata/decoder.rs | 4 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs index f09474ff4d3..d111471f53d 100644 --- a/src/librustc_data_structures/sync.rs +++ b/src/librustc_data_structures/sync.rs @@ -497,13 +497,15 @@ impl<T> Once<T> { /// If the value was already initialized the closure is not called and `false` is returned, /// otherwise if the value from the closure initializes the inner value, `true` is returned #[inline] - pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> bool { - let mut lock = self.0.lock(); - if lock.is_some() { - return false; + pub fn init_locking<F: FnOnce() -> T>(&self, f: F) -> &T { + { + let mut lock = self.0.lock(); + if lock.is_none() { + *lock = Some(f()); + } } - *lock = Some(f()); - true + + self.borrow() } /// Tries to initialize the inner value by calling the closure without ensuring that no-one diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index b1110ce80a8..c5954e1ea1d 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -1351,9 +1351,7 @@ impl<'a, 'tcx> CrateMetadata { translated_source_file: local_version, } }).collect() - }); - - self.source_map_import_info.borrow() + }) } /// Get the `DepNodeIndex` corresponding this crate. The result of this |
