Move visit_id
calls.
In `walk_item`, we call `visit_id` on every item kind. For most of them we do it directly in `walk_item`. But for `ItemKind::Mod`, `ItemKind::Enum`, and `ItemKind::Use` we instead do it in the `walk_*` function called (via the `visit_*` function) from `walk_item`. I can see no reason for this inconsistency, so this commit makes those three cases like all the other cases, moving the `visit_id` calls into `walk_item`. This also avoids the need for a few `HirId` arguments.
This commit is contained in:
parent
98a48781fe
commit
872ac73f59
5 changed files with 14 additions and 21 deletions
|
@ -316,8 +316,8 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_ident(&mut self, ident: Ident) -> Self::Result {
|
fn visit_ident(&mut self, ident: Ident) -> Self::Result {
|
||||||
walk_ident(self, ident)
|
walk_ident(self, ident)
|
||||||
}
|
}
|
||||||
fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, n: HirId) -> Self::Result {
|
fn visit_mod(&mut self, m: &'v Mod<'v>, _s: Span, _n: HirId) -> Self::Result {
|
||||||
walk_mod(self, m, n)
|
walk_mod(self, m)
|
||||||
}
|
}
|
||||||
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result {
|
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) -> Self::Result {
|
||||||
walk_foreign_item(self, i)
|
walk_foreign_item(self, i)
|
||||||
|
@ -464,8 +464,8 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_field_def(&mut self, s: &'v FieldDef<'v>) -> Self::Result {
|
fn visit_field_def(&mut self, s: &'v FieldDef<'v>) -> Self::Result {
|
||||||
walk_field_def(self, s)
|
walk_field_def(self, s)
|
||||||
}
|
}
|
||||||
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef<'v>, item_id: HirId) -> Self::Result {
|
fn visit_enum_def(&mut self, enum_definition: &'v EnumDef<'v>) -> Self::Result {
|
||||||
walk_enum_def(self, enum_definition, item_id)
|
walk_enum_def(self, enum_definition)
|
||||||
}
|
}
|
||||||
fn visit_variant(&mut self, v: &'v Variant<'v>) -> Self::Result {
|
fn visit_variant(&mut self, v: &'v Variant<'v>) -> Self::Result {
|
||||||
walk_variant(self, v)
|
walk_variant(self, v)
|
||||||
|
@ -539,6 +539,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||||
visit_opt!(visitor, visit_name, orig_name);
|
visit_opt!(visitor, visit_name, orig_name);
|
||||||
}
|
}
|
||||||
ItemKind::Use(ref path, _) => {
|
ItemKind::Use(ref path, _) => {
|
||||||
|
try_visit!(visitor.visit_id(item.hir_id()));
|
||||||
try_visit!(visitor.visit_use(path, item.hir_id()));
|
try_visit!(visitor.visit_use(path, item.hir_id()));
|
||||||
}
|
}
|
||||||
ItemKind::Static(ref typ, _, body) => {
|
ItemKind::Static(ref typ, _, body) => {
|
||||||
|
@ -566,7 +567,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||||
try_visit!(visitor.visit_id(item.hir_id()));
|
try_visit!(visitor.visit_id(item.hir_id()));
|
||||||
}
|
}
|
||||||
ItemKind::Mod(ref module) => {
|
ItemKind::Mod(ref module) => {
|
||||||
// `visit_mod()` takes care of visiting the `Item`'s `HirId`.
|
try_visit!(visitor.visit_id(item.hir_id()));
|
||||||
try_visit!(visitor.visit_mod(module, item.span, item.hir_id()));
|
try_visit!(visitor.visit_mod(module, item.span, item.hir_id()));
|
||||||
}
|
}
|
||||||
ItemKind::ForeignMod { abi: _, items } => {
|
ItemKind::ForeignMod { abi: _, items } => {
|
||||||
|
@ -587,9 +588,9 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
}
|
}
|
||||||
ItemKind::Enum(ref enum_definition, ref generics) => {
|
ItemKind::Enum(ref enum_definition, ref generics) => {
|
||||||
|
try_visit!(visitor.visit_id(item.hir_id()));
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
// `visit_enum_def()` takes care of visiting the `Item`'s `HirId`.
|
try_visit!(visitor.visit_enum_def(enum_definition));
|
||||||
try_visit!(visitor.visit_enum_def(enum_definition, item.hir_id()));
|
|
||||||
}
|
}
|
||||||
ItemKind::Impl(Impl {
|
ItemKind::Impl(Impl {
|
||||||
constness: _,
|
constness: _,
|
||||||
|
@ -638,12 +639,7 @@ pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) -> V::Resul
|
||||||
visitor.visit_name(ident.name)
|
visitor.visit_name(ident.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_mod<'v, V: Visitor<'v>>(
|
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod<'v>) -> V::Result {
|
||||||
visitor: &mut V,
|
|
||||||
module: &'v Mod<'v>,
|
|
||||||
mod_hir_id: HirId,
|
|
||||||
) -> V::Result {
|
|
||||||
try_visit!(visitor.visit_id(mod_hir_id));
|
|
||||||
walk_list!(visitor, visit_nested_item, module.item_ids.iter().copied());
|
walk_list!(visitor, visit_nested_item, module.item_ids.iter().copied());
|
||||||
V::Result::output()
|
V::Result::output()
|
||||||
}
|
}
|
||||||
|
@ -1145,7 +1141,6 @@ pub fn walk_use<'v, V: Visitor<'v>>(
|
||||||
path: &'v UsePath<'v>,
|
path: &'v UsePath<'v>,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
try_visit!(visitor.visit_id(hir_id));
|
|
||||||
let UsePath { segments, ref res, span } = *path;
|
let UsePath { segments, ref res, span } = *path;
|
||||||
for &res in res {
|
for &res in res {
|
||||||
try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id));
|
try_visit!(visitor.visit_path(&Path { segments, res, span }, hir_id));
|
||||||
|
@ -1326,9 +1321,7 @@ pub fn walk_field_def<'v, V: Visitor<'v>>(
|
||||||
pub fn walk_enum_def<'v, V: Visitor<'v>>(
|
pub fn walk_enum_def<'v, V: Visitor<'v>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
enum_definition: &'v EnumDef<'v>,
|
enum_definition: &'v EnumDef<'v>,
|
||||||
item_id: HirId,
|
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
try_visit!(visitor.visit_id(item_id));
|
|
||||||
walk_list!(visitor, visit_variant, enum_definition.variants);
|
walk_list!(visitor, visit_variant, enum_definition.variants);
|
||||||
V::Result::output()
|
V::Result::output()
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
||||||
|
|
||||||
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: HirId) {
|
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: HirId) {
|
||||||
lint_callback!(self, check_mod, m, n);
|
lint_callback!(self, check_mod, m, n);
|
||||||
hir_visit::walk_mod(self, m, n);
|
hir_visit::walk_mod(self, m);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1356,7 +1356,7 @@ impl<'hir> Visitor<'hir> for ItemCollector<'hir> {
|
||||||
self.submodules.push(item.owner_id);
|
self.submodules.push(item.owner_id);
|
||||||
// A module collector does not recurse inside nested modules.
|
// A module collector does not recurse inside nested modules.
|
||||||
if self.crate_collector {
|
if self.crate_collector {
|
||||||
intravisit::walk_mod(self, module, item.hir_id());
|
intravisit::walk_mod(self, module);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
intravisit::walk_item(self, item)
|
intravisit::walk_item(self, item)
|
||||||
|
|
|
@ -255,9 +255,9 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
hir_visit::walk_body(self, b);
|
hir_visit::walk_body(self, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &'v hir::Mod<'v>, _s: Span, n: HirId) {
|
fn visit_mod(&mut self, m: &'v hir::Mod<'v>, _s: Span, _n: HirId) {
|
||||||
self.record("Mod", None, m);
|
self.record("Mod", None, m);
|
||||||
hir_visit::walk_mod(self, m, n)
|
hir_visit::walk_mod(self, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) {
|
fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem<'v>) {
|
||||||
|
|
|
@ -253,7 +253,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
|
||||||
// If it's a "mod foo {}", we want to look to its documentation page.
|
// If it's a "mod foo {}", we want to look to its documentation page.
|
||||||
self.extract_info_from_hir_id(id);
|
self.extract_info_from_hir_id(id);
|
||||||
}
|
}
|
||||||
intravisit::walk_mod(self, m, id);
|
intravisit::walk_mod(self, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue