aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/ty.rs26
-rw-r--r--crates/ra_hir/src/ty/infer/unify.rs18
-rw-r--r--crates/ra_hir/src/ty/lower.rs6
-rw-r--r--crates/ra_hir/src/util.rs15
4 files changed, 23 insertions, 42 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index bf7445ea3..cc9746f6d 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -17,7 +17,7 @@ use std::sync::Arc;
17use std::{fmt, iter, mem}; 17use std::{fmt, iter, mem};
18 18
19use crate::{ 19use crate::{
20 db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_arc_slice, Adt, Crate, 20 db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_slice, Adt, Crate,
21 DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias, 21 DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias,
22}; 22};
23use display::{HirDisplay, HirFormatter}; 23use display::{HirDisplay, HirFormatter};
@@ -308,11 +308,9 @@ impl Substs {
308 } 308 }
309 309
310 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 310 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
311 make_mut_arc_slice(&mut self.0, |s| { 311 for t in make_mut_slice(&mut self.0) {
312 for t in s { 312 t.walk_mut(f);
313 t.walk_mut(f); 313 }
314 }
315 });
316 } 314 }
317 315
318 pub fn as_single(&self) -> &Ty { 316 pub fn as_single(&self) -> &Ty {
@@ -538,11 +536,9 @@ impl TypeWalk for FnSig {
538 } 536 }
539 537
540 fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 538 fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
541 make_mut_arc_slice(&mut self.params_and_return, |s| { 539 for t in make_mut_slice(&mut self.params_and_return) {
542 for t in s { 540 t.walk_mut(f);
543 t.walk_mut(f); 541 }
544 }
545 });
546 } 542 }
547} 543}
548 544
@@ -752,11 +748,9 @@ impl TypeWalk for Ty {
752 p_ty.parameters.walk_mut(f); 748 p_ty.parameters.walk_mut(f);
753 } 749 }
754 Ty::Dyn(predicates) | Ty::Opaque(predicates) => { 750 Ty::Dyn(predicates) | Ty::Opaque(predicates) => {
755 make_mut_arc_slice(predicates, |s| { 751 for p in make_mut_slice(predicates) {
756 for p in s { 752 p.walk_mut(f);
757 p.walk_mut(f); 753 }
758 }
759 });
760 } 754 }
761 Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} 755 Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {}
762 } 756 }
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs
index 5e86ed260..014c7981f 100644
--- a/crates/ra_hir/src/ty/infer/unify.rs
+++ b/crates/ra_hir/src/ty/infer/unify.rs
@@ -6,7 +6,7 @@ use crate::ty::{
6 Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, 6 Canonical, InEnvironment, InferTy, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty,
7 TypeWalk, 7 TypeWalk,
8}; 8};
9use crate::util::make_mut_arc_slice; 9use crate::util::make_mut_slice;
10 10
11impl<'a, D: HirDatabase> InferenceContext<'a, D> { 11impl<'a, D: HirDatabase> InferenceContext<'a, D> {
12 pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> 12 pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D>
@@ -76,11 +76,9 @@ where
76 } 76 }
77 77
78 fn do_canonicalize_trait_ref(&mut self, mut trait_ref: TraitRef) -> TraitRef { 78 fn do_canonicalize_trait_ref(&mut self, mut trait_ref: TraitRef) -> TraitRef {
79 make_mut_arc_slice(&mut trait_ref.substs.0, |tys| { 79 for ty in make_mut_slice(&mut trait_ref.substs.0) {
80 for ty in tys { 80 *ty = self.do_canonicalize_ty(ty.clone());
81 *ty = self.do_canonicalize_ty(ty.clone()); 81 }
82 }
83 });
84 trait_ref 82 trait_ref
85 } 83 }
86 84
@@ -92,11 +90,9 @@ where
92 } 90 }
93 91
94 fn do_canonicalize_projection_ty(&mut self, mut projection_ty: ProjectionTy) -> ProjectionTy { 92 fn do_canonicalize_projection_ty(&mut self, mut projection_ty: ProjectionTy) -> ProjectionTy {
95 make_mut_arc_slice(&mut projection_ty.parameters.0, |params| { 93 for ty in make_mut_slice(&mut projection_ty.parameters.0) {
96 for ty in params { 94 *ty = self.do_canonicalize_ty(ty.clone());
97 *ty = self.do_canonicalize_ty(ty.clone()); 95 }
98 }
99 });
100 projection_ty 96 projection_ty
101 } 97 }
102 98
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index 639518f27..366556134 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -22,7 +22,7 @@ use crate::{
22 resolve::{Resolver, TypeNs}, 22 resolve::{Resolver, TypeNs},
23 ty::Adt, 23 ty::Adt,
24 type_ref::{TypeBound, TypeRef}, 24 type_ref::{TypeBound, TypeRef},
25 util::make_mut_arc_slice, 25 util::make_mut_slice,
26 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, 26 BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField,
27 Trait, TypeAlias, Union, 27 Trait, TypeAlias, Union,
28}; 28};
@@ -391,9 +391,7 @@ impl TraitRef {
391 ) -> Self { 391 ) -> Self {
392 let mut substs = TraitRef::substs_from_path(db, resolver, segment, resolved); 392 let mut substs = TraitRef::substs_from_path(db, resolver, segment, resolved);
393 if let Some(self_ty) = explicit_self_ty { 393 if let Some(self_ty) = explicit_self_ty {
394 make_mut_arc_slice(&mut substs.0, |substs| { 394 make_mut_slice(&mut substs.0)[0] = self_ty;
395 substs[0] = self_ty;
396 });
397 } 395 }
398 TraitRef { trait_: resolved, substs } 396 TraitRef { trait_: resolved, substs }
399 } 397 }
diff --git a/crates/ra_hir/src/util.rs b/crates/ra_hir/src/util.rs
index 46f423c91..0095ee45d 100644
--- a/crates/ra_hir/src/util.rs
+++ b/crates/ra_hir/src/util.rs
@@ -4,16 +4,9 @@ use std::sync::Arc;
4 4
5/// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices). 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. 6/// The underlying values are cloned if there are other strong references.
7pub(crate) fn make_mut_arc_slice<T: Clone, R>( 7pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
8 a: &mut Arc<[T]>, 8 if Arc::get_mut(a).is_none() {
9 f: impl FnOnce(&mut [T]) -> R, 9 *a = a.iter().cloned().collect();
10) -> R {
11 if let Some(s) = Arc::get_mut(a) {
12 f(s)
13 } else {
14 let mut v = a.to_vec();
15 let r = f(&mut v);
16 *a = Arc::from(v);
17 r
18 } 10 }
11 Arc::get_mut(a).unwrap()
19} 12}