diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index d161735e8..fc4909d11 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -17,8 +17,8 @@ use std::sync::Arc; | |||
17 | use std::{fmt, iter, mem}; | 17 | use std::{fmt, iter, mem}; |
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | db::HirDatabase, expr::ExprId, type_ref::Mutability, Adt, Crate, DefWithBody, GenericParams, | 20 | db::HirDatabase, expr::ExprId, type_ref::Mutability, util::make_mut_arc_slice, Adt, Crate, |
21 | HasGenericParams, Name, Trait, TypeAlias, | 21 | DefWithBody, GenericParams, HasGenericParams, Name, Trait, TypeAlias, |
22 | }; | 22 | }; |
23 | use display::{HirDisplay, HirFormatter}; | 23 | use display::{HirDisplay, HirFormatter}; |
24 | 24 | ||
@@ -308,12 +308,11 @@ 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 | // Without an Arc::make_mut_slice, we can't avoid the clone here: | 311 | make_mut_arc_slice(&mut self.0, |s| { |
312 | let mut v: Vec<_> = self.0.iter().cloned().collect(); | 312 | for t in s { |
313 | for t in &mut v { | 313 | t.walk_mut(f); |
314 | t.walk_mut(f); | 314 | } |
315 | } | 315 | }); |
316 | self.0 = v.into(); | ||
317 | } | 316 | } |
318 | 317 | ||
319 | pub fn as_single(&self) -> &Ty { | 318 | pub fn as_single(&self) -> &Ty { |
@@ -541,12 +540,11 @@ impl TypeWalk for FnSig { | |||
541 | } | 540 | } |
542 | 541 | ||
543 | fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | 542 | fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { |
544 | // Without an Arc::make_mut_slice, we can't avoid the clone here: | 543 | make_mut_arc_slice(&mut self.params_and_return, |s| { |
545 | let mut v: Vec<_> = self.params_and_return.iter().cloned().collect(); | 544 | for t in s { |
546 | for t in &mut v { | 545 | t.walk_mut(f); |
547 | t.walk_mut(f); | 546 | } |
548 | } | 547 | }); |
549 | self.params_and_return = v.into(); | ||
550 | } | 548 | } |
551 | } | 549 | } |
552 | 550 | ||
@@ -756,11 +754,11 @@ impl TypeWalk for Ty { | |||
756 | p_ty.parameters.walk_mut(f); | 754 | p_ty.parameters.walk_mut(f); |
757 | } | 755 | } |
758 | Ty::Dyn(predicates) | Ty::Opaque(predicates) => { | 756 | Ty::Dyn(predicates) | Ty::Opaque(predicates) => { |
759 | let mut v: Vec<_> = predicates.iter().cloned().collect(); | 757 | make_mut_arc_slice(predicates, |s| { |
760 | for p in &mut v { | 758 | for p in s { |
761 | p.walk_mut(f); | 759 | p.walk_mut(f); |
762 | } | 760 | } |
763 | *predicates = v.into(); | 761 | }); |
764 | } | 762 | } |
765 | Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} | 763 | Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} |
766 | } | 764 | } |