Address comments

This commit is contained in:
John Kåre Alsaker 2019-01-11 04:58:46 +01:00
parent 468254b38f
commit e69c2c75d6
7 changed files with 20 additions and 26 deletions

View File

@ -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()
);

View File

@ -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);

View File

@ -507,32 +507,29 @@ impl<'hir> Map<'hir> {
&self.forest.krate.attrs
}
pub fn visit_module_item_likes<V>(&self, module: DefId, visitor: &mut V)
pub fn visit_item_likes_in_module<V>(&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));
}
}

View File

@ -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<'_>) {

View File

@ -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,

View File

@ -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> {

View File

@ -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()
);