rustc_middle/hir/
nested_filter.rs

1use rustc_hir::intravisit::nested_filter::NestedFilter;
2
3use crate::ty::TyCtxt;
4
5/// Do not visit nested item-like things, but visit nested things
6/// that are inside of an item-like.
7///
8/// Notably, possible occurrences of bodies in non-item-like things
9/// include: closures/coroutines, inline `const {}` blocks, and
10/// constant arguments of types, e.g. in `let _: [(); /* HERE */];`.
11///
12/// **This is the most common choice.** A very common pattern is
13/// to use `visit_all_item_likes_in_crate()` as an outer loop,
14/// and to have the visitor that visits the contents of each item
15/// using this setting.
16pub struct OnlyBodies(());
17impl<'tcx> NestedFilter<'tcx> for OnlyBodies {
18    type MaybeTyCtxt = TyCtxt<'tcx>;
19    const INTER: bool = false;
20    const INTRA: bool = true;
21}
22
23/// Visits all nested things, including item-likes.
24///
25/// **This is an unusual choice.** It is used when you want to
26/// process everything within their lexical context. Typically you
27/// kick off the visit by doing `walk_krate()`.
28pub struct All(());
29impl<'tcx> NestedFilter<'tcx> for All {
30    type MaybeTyCtxt = TyCtxt<'tcx>;
31    const INTER: bool = true;
32    const INTRA: bool = true;
33}