|
38 | 38 | //! might provide custom handling only for some types of interest, or only
|
39 | 39 | //! for some variants of each type of interest, and then use default
|
40 | 40 | //! traversal for the remaining cases.
|
| 41 | +//! |
| 42 | +//! For example, if you have `struct S(Ty, U)` where `S: TypeFoldable` and `U: |
| 43 | +//! TypeFoldable`, and an instance `S(ty, u)`, it would be visited like so: |
| 44 | +//! ``` |
| 45 | +//! s.visit_with(visitor) calls |
| 46 | +//! - s.super_visit_with(visitor) calls |
| 47 | +//! - ty.visit_with(visitor) calls |
| 48 | +//! - visitor.visit_ty(ty) may call |
| 49 | +//! - ty.super_visit_with(visitor) |
| 50 | +//! - u.visit_with(visitor) |
| 51 | +//! ``` |
41 | 52 | use crate::mir;
|
42 | 53 | use crate::ty::{self, flags::FlagComputation, Binder, Ty, TyCtxt, TypeFlags};
|
43 | 54 | use rustc_hir::def_id::DefId;
|
@@ -96,7 +107,7 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
|
96 | 107 | /// For types of interest (such as `Ty`), this default is overridden with a
|
97 | 108 | /// method that calls a visitor method specifically for that type (such as
|
98 | 109 | /// `V::visit_ty`). This is where control transfers from `TypeFoldable` to
|
99 |
| - /// `TypeFolder`. |
| 110 | + /// `TypeVisitor`. |
100 | 111 | ///
|
101 | 112 | /// For other types, this default is used.
|
102 | 113 | fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
|
@@ -349,7 +360,7 @@ where
|
349 | 360 |
|
350 | 361 | /// This trait is implemented for every visiting traversal. There is a visit
|
351 | 362 | /// method defined for every type of interest. Each such method has a default
|
352 |
| -/// that does a non-custom visit. |
| 363 | +/// that recurses into the type's fields in a non-custom fashion. |
353 | 364 | pub trait TypeVisitor<'tcx>: Sized {
|
354 | 365 | type BreakTy = !;
|
355 | 366 |
|
|
0 commit comments