fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir>;
}
+/// An erased version of `Map<'hir>`, using dynamic dispatch.
+/// NOTE: This type is effectively only usable with `NestedVisitorMap::None`.
+pub struct ErasedMap<'hir>(&'hir dyn Map<'hir>);
+
+impl<'hir> Map<'hir> for ErasedMap<'hir> {
+ fn body(&self, id: BodyId) -> &'hir Body<'hir> {
+ self.0.body(id)
+ }
+ fn item(&self, id: HirId) -> &'hir Item<'hir> {
+ self.0.item(id)
+ }
+ fn trait_item(&self, id: TraitItemId) -> &'hir TraitItem<'hir> {
+ self.0.trait_item(id)
+ }
+ fn impl_item(&self, id: ImplItemId) -> &'hir ImplItem<'hir> {
+ self.0.impl_item(id)
+ }
+}
+
/// Specifies what nested things a visitor wants to visit. The most
/// common choice is `OnlyBodies`, which will cause the visitor to
/// visit fn bodies for fns that it encounters, but skip over nested
///
/// See the comments on `ItemLikeVisitor` for more details on the overall
/// visit strategy.
-pub enum NestedVisitorMap<'this, M> {
+pub enum NestedVisitorMap<M> {
/// Do not visit any nested things. When you add a new
/// "non-nested" thing, you will want to audit such uses to see if
/// they remain valid.
/// to use `visit_all_item_likes()` as an outer loop,
/// and to have the visitor that visits the contents of each item
/// using this setting.
- OnlyBodies(&'this M),
+ OnlyBodies(M),
/// Visits all nested things, including item-likes.
///
/// **This is an unusual choice.** It is used when you want to
/// process everything within their lexical context. Typically you
/// kick off the visit by doing `walk_krate()`.
- All(&'this M),
+ All(M),
}
-impl<'this, M> NestedVisitorMap<'this, M> {
+impl<M> NestedVisitorMap<M> {
/// Returns the map to use for an "intra item-like" thing (if any).
/// E.g., function body.
- fn intra(self) -> Option<&'this M> {
+ fn intra(self) -> Option<M> {
match self {
NestedVisitorMap::None => None,
NestedVisitorMap::OnlyBodies(map) => Some(map),
/// Returns the map to use for an "item-like" thing (if any).
/// E.g., item, impl-item.
- fn inter(self) -> Option<&'this M> {
+ fn inter(self) -> Option<M> {
match self {
NestedVisitorMap::None => None,
NestedVisitorMap::OnlyBodies(_) => None,
/// `panic!()`. This way, if a new `visit_nested_XXX` variant is
/// added in the future, we will see the panic in your code and
/// fix it appropriately.
- fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map>;
+ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map>;
/// Invoked when a nested item is encountered. By default does
/// nothing unless you override `nested_visit_map` to return other than
/// Walks the contents of a crate. See also `Crate::visit_all_items`.
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
- visitor.visit_mod(&krate.module, krate.span, CRATE_HIR_ID);
- walk_list!(visitor, visit_attribute, krate.attrs);
+ visitor.visit_mod(&krate.item.module, krate.item.span, CRATE_HIR_ID);
+ walk_list!(visitor, visit_attribute, krate.item.attrs);
walk_list!(visitor, visit_macro_def, krate.exported_macros);
}
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
visitor.visit_id(macro_def.hir_id);
- visitor.visit_name(macro_def.span, macro_def.name);
+ visitor.visit_ident(macro_def.ident);
walk_list!(visitor, visit_attribute, macro_def.attrs);
}
visitor.visit_ty(ty);
walk_list!(visitor, visit_nested_body, default);
}
- TraitItemKind::Fn(ref sig, TraitMethod::Required(param_names)) => {
+ TraitItemKind::Fn(ref sig, TraitFn::Required(param_names)) => {
visitor.visit_id(trait_item.hir_id);
visitor.visit_fn_decl(&sig.decl);
for ¶m_name in param_names {
visitor.visit_ident(param_name);
}
}
- TraitItemKind::Fn(ref sig, TraitMethod::Provided(body_id)) => {
+ TraitItemKind::Fn(ref sig, TraitFn::Provided(body_id)) => {
visitor.visit_fn(
FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs),
&sig.decl,
visitor.visit_ty(ty);
visitor.visit_nested_body(body);
}
- ImplItemKind::Method(ref sig, body_id) => {
+ ImplItemKind::Fn(ref sig, body_id) => {
visitor.visit_fn(
FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs),
&sig.decl,