diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index d161735e8..cc9746f6d 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_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,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 | // Without an Arc::make_mut_slice, we can't avoid the clone here: | 311 | for t in make_mut_slice(&mut self.0) { |
312 | let mut v: Vec<_> = self.0.iter().cloned().collect(); | ||
313 | for t in &mut v { | ||
314 | t.walk_mut(f); | 312 | t.walk_mut(f); |
315 | } | 313 | } |
316 | self.0 = v.into(); | ||
317 | } | 314 | } |
318 | 315 | ||
319 | pub fn as_single(&self) -> &Ty { | 316 | pub fn as_single(&self) -> &Ty { |
@@ -330,8 +327,7 @@ impl Substs { | |||
330 | .params_including_parent() | 327 | .params_including_parent() |
331 | .into_iter() | 328 | .into_iter() |
332 | .map(|p| Ty::Param { idx: p.idx, name: p.name.clone() }) | 329 | .map(|p| Ty::Param { idx: p.idx, name: p.name.clone() }) |
333 | .collect::<Vec<_>>() | 330 | .collect(), |
334 | .into(), | ||
335 | ) | 331 | ) |
336 | } | 332 | } |
337 | 333 | ||
@@ -342,8 +338,7 @@ impl Substs { | |||
342 | .params_including_parent() | 338 | .params_including_parent() |
343 | .into_iter() | 339 | .into_iter() |
344 | .map(|p| Ty::Bound(p.idx)) | 340 | .map(|p| Ty::Bound(p.idx)) |
345 | .collect::<Vec<_>>() | 341 | .collect(), |
346 | .into(), | ||
347 | ) | 342 | ) |
348 | } | 343 | } |
349 | 344 | ||
@@ -541,12 +536,9 @@ impl TypeWalk for FnSig { | |||
541 | } | 536 | } |
542 | 537 | ||
543 | fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | 538 | 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: | 539 | for t in make_mut_slice(&mut self.params_and_return) { |
545 | let mut v: Vec<_> = self.params_and_return.iter().cloned().collect(); | ||
546 | for t in &mut v { | ||
547 | t.walk_mut(f); | 540 | t.walk_mut(f); |
548 | } | 541 | } |
549 | self.params_and_return = v.into(); | ||
550 | } | 542 | } |
551 | } | 543 | } |
552 | 544 | ||
@@ -756,11 +748,9 @@ impl TypeWalk for Ty { | |||
756 | p_ty.parameters.walk_mut(f); | 748 | p_ty.parameters.walk_mut(f); |
757 | } | 749 | } |
758 | Ty::Dyn(predicates) | Ty::Opaque(predicates) => { | 750 | Ty::Dyn(predicates) | Ty::Opaque(predicates) => { |
759 | let mut v: Vec<_> = predicates.iter().cloned().collect(); | 751 | for p in make_mut_slice(predicates) { |
760 | for p in &mut v { | ||
761 | p.walk_mut(f); | 752 | p.walk_mut(f); |
762 | } | 753 | } |
763 | *predicates = v.into(); | ||
764 | } | 754 | } |
765 | Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} | 755 | Ty::Param { .. } | Ty::Bound(_) | Ty::Infer(_) | Ty::Unknown => {} |
766 | } | 756 | } |