From e69c2c75d6d279ffd636634b0cde2529bbf8b6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Fri, 11 Jan 2019 04:58:46 +0100 Subject: [PATCH] Address comments --- src/librustc/hir/check_attr.rs | 4 ++-- src/librustc/hir/lowering.rs | 15 ++++++--------- src/librustc/hir/map/mod.rs | 15 ++++++--------- src/librustc/middle/stability.rs | 4 ++-- src/librustc_passes/loops.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/collect.rs | 2 +- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 2cce8e0f9c9..a214ec88c66 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -388,8 +388,8 @@ fn is_c_like_enum(item: &hir::Item) -> bool { } } -pub fn check_mod_attrs<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { - tcx.hir().visit_module_item_likes( +fn check_mod_attrs<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { + tcx.hir().visit_item_likes_in_module( module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor() ); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 6957c97931b..8badcbfc1b3 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -362,15 +362,6 @@ impl<'a> LoweringContext<'a> { } impl<'lcx, 'interner> Visitor<'lcx> for MiscCollector<'lcx, 'interner> { - fn visit_mod(&mut self, m: &'lcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { - self.lctx.modules.insert(n, hir::ModuleItems { - items: BTreeSet::new(), - trait_items: BTreeSet::new(), - impl_items: BTreeSet::new(), - }); - visit::walk_mod(self, m); - } - fn visit_item(&mut self, item: &'lcx Item) { self.lctx.allocate_hir_id_counter(item.id, item); @@ -430,6 +421,12 @@ impl<'a> LoweringContext<'a> { impl<'lcx, 'interner> Visitor<'lcx> for ItemLowerer<'lcx, 'interner> { fn visit_mod(&mut self, m: &'lcx Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { + self.lctx.modules.insert(n, hir::ModuleItems { + items: BTreeSet::new(), + trait_items: BTreeSet::new(), + impl_items: BTreeSet::new(), + }); + let old = self.lctx.current_module; self.lctx.current_module = n; visit::walk_mod(self, m); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 0d55b4fdb74..513e18b1373 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -507,32 +507,29 @@ impl<'hir> Map<'hir> { &self.forest.krate.attrs } - pub fn visit_module_item_likes(&self, module: DefId, visitor: &mut V) + pub fn visit_item_likes_in_module(&self, module: DefId, visitor: &mut V) where V: ItemLikeVisitor<'hir> { let node_id = self.as_local_node_id(module).unwrap(); // Read the module so we'll be re-executed if new items // appear immediately under in the module. If some new item appears - // in some nested item in the module, we'll be re-executed due to the reads - // in the loops below + // in some nested item in the module, we'll be re-executed due to reads + // in the expect_* calls the loops below self.read(node_id); let module = &self.forest.krate.modules[&node_id]; for id in &module.items { - self.read(*id); - visitor.visit_item(&self.forest.krate.items[id]); + visitor.visit_item(self.expect_item(*id)); } for id in &module.trait_items { - self.read(id.node_id); - visitor.visit_trait_item(&self.forest.krate.trait_items[id]); + visitor.visit_trait_item(self.expect_trait_item(id.node_id)); } for id in &module.impl_items { - self.read(id.node_id); - visitor.visit_impl_item(&self.forest.krate.impl_items[id]); + visitor.visit_impl_item(self.expect_impl_item(id.node_id)); } } diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index ad275ff2faa..918e286c435 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -464,8 +464,8 @@ pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { /// Cross-references the feature names of unstable APIs with enabled /// features and possibly prints errors. -pub fn check_mod_unstable_api_usage<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { - tcx.hir().visit_module_item_likes(module_def_id, &mut Checker { tcx }.as_deep_visitor()); +fn check_mod_unstable_api_usage<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { + tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx }.as_deep_visitor()); } pub fn provide(providers: &mut Providers<'_>) { diff --git a/src/librustc_passes/loops.rs b/src/librustc_passes/loops.rs index 712fa84ccd9..7d9165a82bc 100644 --- a/src/librustc_passes/loops.rs +++ b/src/librustc_passes/loops.rs @@ -52,8 +52,8 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { } } -pub fn check_mod_loops<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { - tcx.hir().visit_module_item_likes(module_def_id, &mut CheckLoopVisitor { +fn check_mod_loops<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { + tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckLoopVisitor { sess: &tcx.sess, hir_map: &tcx.hir(), cx: Normal, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index d008c80267c..111055e6123 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -708,7 +708,7 @@ pub fn check_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), Err } fn check_mod_item_types<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { - tcx.hir().visit_module_item_likes(module_def_id, &mut CheckItemTypesVisitor { tcx }); + tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx }); } pub fn check_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Result<(), CompileIncomplete> { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 9bdc0bdc2e9..52fa9e5f991 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -62,7 +62,7 @@ pub fn collect_item_types<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { } fn collect_mod_item_types<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId) { - tcx.hir().visit_module_item_likes( + tcx.hir().visit_item_likes_in_module( module_def_id, &mut CollectItemTypesVisitor { tcx }.as_deep_visitor() );