Skip to content

Commit bbe8e9e

Browse files
committed
Add comment explaining why it is called intravisit
1 parent f417ffc commit bbe8e9e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/librustc_front/intravisit.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
//! call `visit::walk_*` to apply the default traversal algorithm, or prevent
1414
//! deeper traversal by doing nothing.
1515
//!
16-
//! Note: it is an important invariant that the default visitor walks the body
17-
//! of a function in "execution order" (more concretely, reverse post-order
18-
//! with respect to the CFG implied by the AST), meaning that if AST node A may
19-
//! execute before AST node B, then A is visited first. The borrow checker in
20-
//! particular relies on this property.
16+
//! When visiting the HIR, the contents of nested items are NOT visited
17+
//! by default. This is different from the AST visitor, which does a deep walk.
18+
//! Hence this module is called `intravisit`; see the method `visit_nested_item`
19+
//! for more details.
2120
//!
22-
//! Note: walking an AST before macro expansion is probably a bad idea. For
23-
//! instance, a walker looking for item names in a module will miss all of
24-
//! those that are created by the expansion of a macro.
21+
//! Note: it is an important invariant that the default visitor walks
22+
//! the body of a function in "execution order" (more concretely,
23+
//! reverse post-order with respect to the CFG implied by the AST),
24+
//! meaning that if AST node A may execute before AST node B, then A
25+
//! is visited first. The borrow checker in particular relies on this
26+
//! property.
2527
2628
use syntax::abi::Abi;
2729
use syntax::ast::{Ident, NodeId, CRATE_NODE_ID, Name, Attribute};
@@ -45,8 +47,10 @@ pub enum FnKind<'a> {
4547
/// the substructure of the input via the corresponding `walk` method;
4648
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
4749
///
48-
/// Note that this visitor does NOT visit nested items by default. If
49-
/// you simply want to visit all items in the crate in some order, you
50+
/// Note that this visitor does NOT visit nested items by default
51+
/// (this is why the module is called `intravisit`, to distinguish it
52+
/// from the AST's `visit` module, which acts differently). If you
53+
/// simply want to visit all items in the crate in some order, you
5054
/// should call `Crate::visit_all_items`. Otherwise, see the comment
5155
/// on `visit_nested_item` for details on how to visit nested items.
5256
///

0 commit comments

Comments
 (0)