diff options
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r-- | crates/ra_hir/src/ty.rs | 53 |
1 files changed, 52 insertions, 1 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 7203a8a10..2dc1de41a 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -449,6 +449,49 @@ impl Ty { | |||
449 | Ty::Tuple(Arc::new([])) | 449 | Ty::Tuple(Arc::new([])) |
450 | } | 450 | } |
451 | 451 | ||
452 | pub fn walk(&self, f: &mut impl FnMut(&Ty)) { | ||
453 | f(self); | ||
454 | match self { | ||
455 | Ty::Slice(t) | Ty::Array(t) => t.walk(f), | ||
456 | Ty::RawPtr(t, _) => t.walk(f), | ||
457 | Ty::Ref(t, _) => t.walk(f), | ||
458 | Ty::Tuple(ts) => { | ||
459 | for t in ts.iter() { | ||
460 | t.walk(f); | ||
461 | } | ||
462 | } | ||
463 | Ty::FnPtr(sig) => { | ||
464 | for input in &sig.input { | ||
465 | input.walk(f); | ||
466 | } | ||
467 | sig.output.walk(f); | ||
468 | } | ||
469 | Ty::FnDef { substs, sig, .. } => { | ||
470 | for input in &sig.input { | ||
471 | input.walk(f); | ||
472 | } | ||
473 | sig.output.walk(f); | ||
474 | for t in substs.0.iter() { | ||
475 | t.walk(f); | ||
476 | } | ||
477 | } | ||
478 | Ty::Adt { substs, .. } => { | ||
479 | for t in substs.0.iter() { | ||
480 | t.walk(f); | ||
481 | } | ||
482 | } | ||
483 | Ty::Bool | ||
484 | | Ty::Char | ||
485 | | Ty::Int(_) | ||
486 | | Ty::Float(_) | ||
487 | | Ty::Str | ||
488 | | Ty::Never | ||
489 | | Ty::Param { .. } | ||
490 | | Ty::Infer(_) | ||
491 | | Ty::Unknown => {} | ||
492 | } | ||
493 | } | ||
494 | |||
452 | fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { | 495 | fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { |
453 | f(self); | 496 | f(self); |
454 | match self { | 497 | match self { |
@@ -491,7 +534,15 @@ impl Ty { | |||
491 | } | 534 | } |
492 | substs.0 = v.into(); | 535 | substs.0 = v.into(); |
493 | } | 536 | } |
494 | _ => {} | 537 | Ty::Bool |
538 | | Ty::Char | ||
539 | | Ty::Int(_) | ||
540 | | Ty::Float(_) | ||
541 | | Ty::Str | ||
542 | | Ty::Never | ||
543 | | Ty::Param { .. } | ||
544 | | Ty::Infer(_) | ||
545 | | Ty::Unknown => {} | ||
495 | } | 546 | } |
496 | } | 547 | } |
497 | 548 | ||