aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/util.rs')
-rw-r--r--crates/ra_hir/src/util.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_hir/src/util.rs b/crates/ra_hir/src/util.rs
new file mode 100644
index 000000000..0095ee45d
--- /dev/null
+++ b/crates/ra_hir/src/util.rs
@@ -0,0 +1,12 @@
1//! Internal utility functions.
2
3use std::sync::Arc;
4
5/// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices).
6/// The underlying values are cloned if there are other strong references.
7pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
8 if Arc::get_mut(a).is_none() {
9 *a = a.iter().cloned().collect();
10 }
11 Arc::get_mut(a).unwrap()
12}