Skip to content

Commit 111df9e

Browse files
committed
Reword comments and rename HIR visiting methods.
1 parent c461f7a commit 111df9e

File tree

18 files changed

+113
-105
lines changed

18 files changed

+113
-105
lines changed

compiler/rustc_hir/src/intravisit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! - Example: Examine each expression to look for its type and do some check or other.
2020
//! - How: Implement `intravisit::Visitor` and override the `NestedFilter` type to
2121
//! `nested_filter::OnlyBodies` (and implement `nested_visit_map`), and use
22-
//! `tcx.hir().deep_visit_all_item_likes(&mut visitor)`. Within your
22+
//! `tcx.hir().visit_all_item_likes_in_crate(&mut visitor)`. Within your
2323
//! `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget to invoke
2424
//! `intravisit::walk_expr()` to keep walking the subparts).
2525
//! - Pro: Visitor methods for any kind of HIR node, not just item-like things.
@@ -190,7 +190,7 @@ use nested_filter::NestedFilter;
190190
/// (this is why the module is called `intravisit`, to distinguish it
191191
/// from the AST's `visit` module, which acts differently). If you
192192
/// simply want to visit all items in the crate in some order, you
193-
/// should call `Crate::visit_all_items`. Otherwise, see the comment
193+
/// should call `tcx.hir().visit_all_item_likes_in_crate`. Otherwise, see the comment
194194
/// on `visit_nested_item` for details on how to visit nested items.
195195
///
196196
/// If you want to ensure that your code handles every variant

compiler/rustc_incremental/src/assert_dep_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
7575
let mut visitor =
7676
IfThisChanged { tcx, if_this_changed: vec![], then_this_would_need: vec![] };
7777
visitor.process_attrs(hir::CRATE_HIR_ID);
78-
tcx.hir().deep_visit_all_item_likes(&mut visitor);
78+
tcx.hir().visit_all_item_likes_in_crate(&mut visitor);
7979
(visitor.if_this_changed, visitor.then_this_would_need)
8080
};
8181

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
419419
return;
420420
}
421421

422-
self.tcx.hir().deep_visit_all_item_likes(self);
422+
self.tcx.hir().visit_all_item_likes_in_crate(self);
423423
}
424424

425425
fn encode_def_path_table(&mut self) {

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ impl<'hir> Map<'hir> {
568568
}
569569
}
570570

571-
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
571+
/// Walks the contents of the local crate. See also `visit_all_item_likes_in_crate`.
572572
pub fn walk_toplevel_module(self, visitor: &mut impl Visitor<'hir>) {
573573
let (top_mod, span, hir_id) = self.get_module(CRATE_DEF_ID);
574574
visitor.visit_mod(top_mod, span, hir_id);
@@ -588,53 +588,61 @@ impl<'hir> Map<'hir> {
588588
}
589589
}
590590

591-
/// Visits all items in the crate in some deterministic (but
592-
/// unspecified) order. If you need to process every item,
593-
/// and care about nesting -- usually because your algorithm
594-
/// follows lexical scoping rules -- then this method is the best choice.
595-
/// If you don't care about nesting, you should use the `tcx.hir_crate_items()` query
596-
/// or `items()` instead.
591+
/// Visits all item-likes in the crate in some deterministic (but unspecified) order. If you
592+
/// need to process every item-like, and don't care about visiting nested items in a particular
593+
/// order then this method is the best choice. If you do care about this nesting, you should
594+
/// use the `tcx.hir().walk_toplevel_module`.
595+
///
596+
/// Note that this function will access HIR for all the item-likes in the crate. If you only
597+
/// need to access some of them, it is usually better to manually loop on the iterators
598+
/// provided by `tcx.hir_crate_items(())`.
597599
///
598600
/// Please see the notes in `intravisit.rs` for more information.
599-
pub fn deep_visit_all_item_likes<V>(self, visitor: &mut V)
601+
pub fn visit_all_item_likes_in_crate<V>(self, visitor: &mut V)
600602
where
601603
V: Visitor<'hir>,
602604
{
603-
let krate = self.krate();
604-
for owner in krate.owners.iter().filter_map(|i| i.as_owner()) {
605-
match owner.node() {
606-
OwnerNode::Item(item) => visitor.visit_item(item),
607-
OwnerNode::ForeignItem(item) => visitor.visit_foreign_item(item),
608-
OwnerNode::ImplItem(item) => visitor.visit_impl_item(item),
609-
OwnerNode::TraitItem(item) => visitor.visit_trait_item(item),
610-
OwnerNode::Crate(_) => {}
611-
}
605+
let krate = self.tcx.hir_crate_items(());
606+
607+
for id in krate.items() {
608+
visitor.visit_item(self.item(id));
609+
}
610+
611+
for id in krate.trait_items() {
612+
visitor.visit_trait_item(self.trait_item(id));
613+
}
614+
615+
for id in krate.impl_items() {
616+
visitor.visit_impl_item(self.impl_item(id));
617+
}
618+
619+
for id in krate.foreign_items() {
620+
visitor.visit_foreign_item(self.foreign_item(id));
612621
}
613622
}
614623

615-
/// If you don't care about nesting, you should use the
616-
/// `tcx.hir_module_items()` query or `module_items()` instead.
617-
/// Please see notes in `deep_visit_all_item_likes`.
618-
pub fn deep_visit_item_likes_in_module<V>(self, module: LocalDefId, visitor: &mut V)
624+
/// This method is the equivalent of `visit_all_item_likes_in_crate` but restricted to
625+
/// item-likes in a single module.
626+
pub fn visit_item_likes_in_module<V>(self, module: LocalDefId, visitor: &mut V)
619627
where
620628
V: Visitor<'hir>,
621629
{
622630
let module = self.tcx.hir_module_items(module);
623631

624-
for id in module.items.iter() {
625-
visitor.visit_item(self.item(*id));
632+
for id in module.items() {
633+
visitor.visit_item(self.item(id));
626634
}
627635

628-
for id in module.trait_items.iter() {
629-
visitor.visit_trait_item(self.trait_item(*id));
636+
for id in module.trait_items() {
637+
visitor.visit_trait_item(self.trait_item(id));
630638
}
631639

632-
for id in module.impl_items.iter() {
633-
visitor.visit_impl_item(self.impl_item(*id));
640+
for id in module.impl_items() {
641+
visitor.visit_impl_item(self.impl_item(id));
634642
}
635643

636-
for id in module.foreign_items.iter() {
637-
visitor.visit_foreign_item(self.foreign_item(*id));
644+
for id in module.foreign_items() {
645+
visitor.visit_foreign_item(self.foreign_item(id));
638646
}
639647
}
640648

compiler/rustc_middle/src/hir/nested_filter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::intravisit::nested_filter::NestedFilter;
88
/// constant arguments of types, e.g. in `let _: [(); /* HERE */];`.
99
///
1010
/// **This is the most common choice.** A very common pattern is
11-
/// to use `deep_visit_all_item_likes()` as an outer loop,
11+
/// to use `visit_all_item_likes_in_crate()` as an outer loop,
1212
/// and to have the visitor that visits the contents of each item
1313
/// using this setting.
1414
pub struct OnlyBodies(());

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> {
173173
intravisit::walk_struct_def(self, v)
174174
}
175175
}
176-
tcx.hir().deep_visit_all_item_likes(&mut GatherCtors { tcx, set: &mut set });
176+
tcx.hir().visit_all_item_likes_in_crate(&mut GatherCtors { tcx, set: &mut set });
177177

178178
set
179179
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ fn check_non_exported_macro_for_invalid_attrs(tcx: TyCtxt<'_>, item: &Item<'_>)
24282428

24292429
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
24302430
let check_attr_visitor = &mut CheckAttrVisitor { tcx };
2431-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, check_attr_visitor);
2431+
tcx.hir().visit_item_likes_in_module(module_def_id, check_attr_visitor);
24322432
if module_def_id.is_top_level_module() {
24332433
check_attr_visitor.check_attributes(CRATE_HIR_ID, DUMMY_SP, Target::Mod, None);
24342434
check_invalid_crate_level_attr(tcx, tcx.hir().krate_attrs());

compiler/rustc_passes/src/check_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl NonConstExpr {
5656

5757
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
5858
let mut vis = CheckConstVisitor::new(tcx);
59-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, &mut vis);
59+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis);
6060
}
6161

6262
pub(crate) fn provide(providers: &mut Providers) {

compiler/rustc_passes/src/hir_id_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
2828
errors: &errors,
2929
};
3030

31-
tcx.hir().deep_visit_item_likes_in_module(module_id, &mut v);
31+
tcx.hir().visit_item_likes_in_module(module_id, &mut v);
3232
});
3333

3434
let errors = errors.into_inner();

compiler/rustc_passes/src/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_>) -> String {
140140
}
141141

142142
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
143-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, &mut IrMaps::new(tcx));
143+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut IrMaps::new(tcx));
144144
}
145145

146146
pub fn provide(providers: &mut Providers) {

compiler/rustc_passes/src/loops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct CheckLoopVisitor<'a, 'hir> {
3131
}
3232

3333
fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
34-
tcx.hir().deep_visit_item_likes_in_module(
34+
tcx.hir().visit_item_likes_in_module(
3535
module_def_id,
3636
&mut CheckLoopVisitor { sess: &tcx.sess, hir_map: tcx.hir(), cx: Normal },
3737
);

compiler/rustc_passes/src/naked_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_span::Span;
1414
use rustc_target::spec::abi::Abi;
1515

1616
fn check_mod_naked_functions(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
17-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, &mut CheckNakedFunctions { tcx });
17+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckNakedFunctions { tcx });
1818
}
1919

2020
pub(crate) fn provide(providers: &mut Providers) {

compiler/rustc_passes/src/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
660660
/// Cross-references the feature names of unstable APIs with enabled
661661
/// features and possibly prints errors.
662662
fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
663-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, &mut Checker { tcx });
663+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx });
664664
}
665665

666666
pub(crate) fn provide(providers: &mut Providers) {
@@ -890,7 +890,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
890890
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
891891
missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
892892
tcx.hir().walk_toplevel_module(&mut missing);
893-
tcx.hir().deep_visit_all_item_likes(&mut missing);
893+
tcx.hir().visit_all_item_likes_in_crate(&mut missing);
894894
}
895895

896896
let declared_lang_features = &tcx.features().declared_lang_features;

compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct OnlySelfBounds(bool);
5959
// Main entry point
6060

6161
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
62-
tcx.hir().deep_visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx });
62+
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CollectItemTypesVisitor { tcx });
6363
}
6464

6565
pub fn provide(providers: &mut Providers) {

src/librustdoc/scrape_examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub(crate) fn run(
303303
// Run call-finder on all items
304304
let mut calls = FxHashMap::default();
305305
let mut finder = FindCalls { calls: &mut calls, tcx, map: tcx.hir(), cx, target_crates };
306-
tcx.hir().deep_visit_all_item_likes(&mut finder);
306+
tcx.hir().visit_all_item_likes_in_crate(&mut finder);
307307

308308
// Sort call locations within a given file in document order
309309
for fn_calls in calls.values_mut() {

src/test/ui/dep-graph/dep-graph-struct-signature.stderr

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ error: no path from `WillChange` to `trait_def`
1616
LL | #[rustc_then_this_would_need(trait_def)]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
error: OK
20-
--> $DIR/dep-graph-struct-signature.rs:32:9
21-
|
22-
LL | #[rustc_then_this_would_need(fn_sig)]
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
2519
error: OK
2620
--> $DIR/dep-graph-struct-signature.rs:36:5
2721
|
@@ -52,36 +46,12 @@ error: OK
5246
LL | #[rustc_then_this_would_need(type_of)]
5347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5448

55-
error: OK
56-
--> $DIR/dep-graph-struct-signature.rs:48:9
57-
|
58-
LL | #[rustc_then_this_would_need(fn_sig)]
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
61-
error: OK
62-
--> $DIR/dep-graph-struct-signature.rs:49:9
63-
|
64-
LL | #[rustc_then_this_would_need(typeck)]
65-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66-
6749
error: OK
6850
--> $DIR/dep-graph-struct-signature.rs:53:5
6951
|
7052
LL | #[rustc_then_this_would_need(type_of)]
7153
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7254

73-
error: OK
74-
--> $DIR/dep-graph-struct-signature.rs:55:9
75-
|
76-
LL | #[rustc_then_this_would_need(fn_sig)]
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
78-
79-
error: OK
80-
--> $DIR/dep-graph-struct-signature.rs:56:9
81-
|
82-
LL | #[rustc_then_this_would_need(typeck)]
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84-
8555
error: OK
8656
--> $DIR/dep-graph-struct-signature.rs:61:9
8757
|
@@ -106,12 +76,6 @@ error: no path from `WillChange` to `type_of`
10676
LL | #[rustc_then_this_would_need(type_of)]
10777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10878

109-
error: no path from `WillChange` to `fn_sig`
110-
--> $DIR/dep-graph-struct-signature.rs:77:9
111-
|
112-
LL | #[rustc_then_this_would_need(fn_sig)]
113-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114-
11579
error: no path from `WillChange` to `fn_sig`
11680
--> $DIR/dep-graph-struct-signature.rs:81:5
11781
|
@@ -130,5 +94,41 @@ error: no path from `WillChange` to `typeck`
13094
LL | #[rustc_then_this_would_need(typeck)]
13195
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13296

97+
error: OK
98+
--> $DIR/dep-graph-struct-signature.rs:32:9
99+
|
100+
LL | #[rustc_then_this_would_need(fn_sig)]
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102+
103+
error: no path from `WillChange` to `fn_sig`
104+
--> $DIR/dep-graph-struct-signature.rs:77:9
105+
|
106+
LL | #[rustc_then_this_would_need(fn_sig)]
107+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
108+
109+
error: OK
110+
--> $DIR/dep-graph-struct-signature.rs:48:9
111+
|
112+
LL | #[rustc_then_this_would_need(fn_sig)]
113+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
115+
error: OK
116+
--> $DIR/dep-graph-struct-signature.rs:49:9
117+
|
118+
LL | #[rustc_then_this_would_need(typeck)]
119+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
120+
121+
error: OK
122+
--> $DIR/dep-graph-struct-signature.rs:55:9
123+
|
124+
LL | #[rustc_then_this_would_need(fn_sig)]
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
126+
127+
error: OK
128+
--> $DIR/dep-graph-struct-signature.rs:56:9
129+
|
130+
LL | #[rustc_then_this_would_need(typeck)]
131+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133133
error: aborting due to 22 previous errors
134134

0 commit comments

Comments
 (0)