Skip to content

Commit

Permalink
remove FIXME(rust-lang#37712) and implement ItemLikeVisitor instead o…
Browse files Browse the repository at this point in the history
…f Visitor
  • Loading branch information
nivkner committed Feb 16, 2018
1 parent b539764 commit 9e64088
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 35 deletions.
32 changes: 12 additions & 20 deletions src/librustc_passes/static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,13 @@ struct CheckCrateVisitor<'a, 'hir: 'a> {
detected_recursive_ids: NodeSet,
}

impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
NestedVisitorMap::None
}

fn visit_item(&mut self, it: &'hir hir::Item) {
match it.node {
impl<'a, 'hir: 'a> hir::itemlikevisit::ItemLikeVisitor<'hir> for CheckCrateVisitor<'a, 'hir> {
fn visit_item(&mut self, item: &'hir hir::Item) {
match item.node {
hir::ItemStatic(..) |
hir::ItemConst(..) => {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_item(it);
recursion_visitor.visit_item(item);
}
hir::ItemEnum(ref enum_def, ref generics) => {
// We could process the whole enum, but handling the variants
Expand All @@ -53,37 +49,34 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
if let Some(_) = variant.node.disr_expr {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.populate_enum_discriminants(enum_def);
recursion_visitor.visit_variant(variant, generics, it.id);
recursion_visitor.visit_variant(variant, generics, item.id);
}
}
}
_ => {}
}
intravisit::walk_item(self, it)
}

fn visit_trait_item(&mut self, ti: &'hir hir::TraitItem) {
match ti.node {
fn visit_trait_item(&mut self, trait_item: &'hir hir::TraitItem) {
match trait_item.node {
hir::TraitItemKind::Const(_, ref default) => {
if let Some(_) = *default {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_trait_item(ti);
recursion_visitor.visit_trait_item(trait_item);
}
}
_ => {}
}
intravisit::walk_trait_item(self, ti)
}

fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) {
match ii.node {
fn visit_impl_item(&mut self, impl_item: &'hir hir::ImplItem) {
match impl_item.node {
hir::ImplItemKind::Const(..) => {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_impl_item(ii);
recursion_visitor.visit_impl_item(impl_item);
}
_ => {}
}
intravisit::walk_impl_item(self, ii)
}
}

Expand All @@ -97,8 +90,7 @@ pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>)
detected_recursive_ids: NodeSet(),
};
sess.track_errors(|| {
// FIXME(#37712) could use ItemLikeVisitor if trait items were item-like
hir_map.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
hir_map.krate().visit_all_item_likes(&mut visitor);
})
}

Expand Down
21 changes: 6 additions & 15 deletions src/librustc_trans_utils/symbol_names_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
//! paths etc in all kinds of annoying scenarios.

use rustc::hir;
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::ty::TyCtxt;
use syntax::ast;

Expand All @@ -34,8 +33,7 @@ pub fn report_symbol_names<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {

tcx.dep_graph.with_ignore(|| {
let mut visitor = SymbolNamesTest { tcx: tcx };
// FIXME(#37712) could use ItemLikeVisitor if trait items were item-like
tcx.hir.krate().visit_all_item_likes(&mut visitor.as_deep_visitor());
tcx.hir.krate().visit_all_item_likes(&mut visitor);
})
}

Expand Down Expand Up @@ -66,23 +64,16 @@ impl<'a, 'tcx> SymbolNamesTest<'a, 'tcx> {
}
}

impl<'a, 'tcx> Visitor<'tcx> for SymbolNamesTest<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
NestedVisitorMap::None
}

impl<'a, 'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for SymbolNamesTest<'a, 'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item) {
self.process_attrs(item.id);
intravisit::walk_item(self, item);
}

fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) {
self.process_attrs(ti.id);
intravisit::walk_trait_item(self, ti)
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) {
self.process_attrs(trait_item.id);
}

fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
self.process_attrs(ii.id);
intravisit::walk_impl_item(self, ii)
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) {
self.process_attrs(impl_item.id);
}
}

0 comments on commit 9e64088

Please sign in to comment.