diff --git a/crates/ide/src/prime_caches.rs b/crates/ide/src/prime_caches.rs index ea0acfaa020..03597f5078b 100644 --- a/crates/ide/src/prime_caches.rs +++ b/crates/ide/src/prime_caches.rs @@ -27,6 +27,7 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) let topo = &graph.crates_in_topological_order(); cb(PrimeCachesProgress::Started); + let _d = stdx::defer(|| cb(PrimeCachesProgress::Finished)); // FIXME: This would be easy to parallelize, since it's in the ideal ordering for that. // Unfortunately rayon prevents panics from propagation out of a `scope`, which breaks @@ -41,6 +42,4 @@ pub(crate) fn prime_caches(db: &RootDatabase, cb: &(dyn Fn(PrimeCachesProgress) }); db.crate_def_map(*krate); } - - cb(PrimeCachesProgress::Finished); } diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index e3eb109156c..857567a853a 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs @@ -179,6 +179,18 @@ pub fn equal_range_by(slice: &[T], mut key: F) -> ops::Range start..start + len } +pub fn defer(f: F) -> impl Drop { + struct D(Option); + impl Drop for D { + fn drop(&mut self) { + if let Some(f) = self.0.take() { + f() + } + } + } + D(Some(f)) +} + #[repr(transparent)] pub struct JodChild(pub std::process::Child);