Skip to content

Commit

Permalink
use LocalDefId in module checking
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Jun 27, 2020
1 parent d8ed1b0 commit a4e7b47
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/librustc_middle/hir/map/mod.rs
Expand Up @@ -451,11 +451,11 @@ impl<'hir> Map<'hir> {
}
}

pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V)
where
V: ItemLikeVisitor<'hir>,
{
let module = self.tcx.hir_module_items(module.expect_local());
let module = self.tcx.hir_module_items(module);

for id in &module.items {
visitor.visit_item(self.expect_item(*id));
Expand Down
26 changes: 13 additions & 13 deletions src/librustc_middle/query/mod.rs
Expand Up @@ -15,11 +15,11 @@ use rustc_query_system::query::QueryDescription;
use rustc_span::symbol::Symbol;
use std::borrow::Cow;

fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
if def_id.is_top_level_module() {
"top-level module".to_string()
} else {
format!("module `{}`", tcx.def_path_str(def_id))
format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
}
}

Expand Down Expand Up @@ -473,49 +473,49 @@ rustc_queries! {

Other {
query lint_mod(key: LocalDefId) -> () {
desc { |tcx| "linting {}", describe_as_module(key.to_def_id(), tcx) }
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
}

/// Checks the attributes in the module.
query check_mod_attrs(key: DefId) -> () {
query check_mod_attrs(key: LocalDefId) -> () {
desc { |tcx| "checking attributes in {}", describe_as_module(key, tcx) }
}

query check_mod_unstable_api_usage(key: DefId) -> () {
query check_mod_unstable_api_usage(key: LocalDefId) -> () {
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
}

/// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
query check_mod_const_bodies(key: DefId) -> () {
query check_mod_const_bodies(key: LocalDefId) -> () {
desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
}

/// Checks the loops in the module.
query check_mod_loops(key: DefId) -> () {
query check_mod_loops(key: LocalDefId) -> () {
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
}

query check_mod_item_types(key: DefId) -> () {
query check_mod_item_types(key: LocalDefId) -> () {
desc { |tcx| "checking item types in {}", describe_as_module(key, tcx) }
}

query check_mod_privacy(key: LocalDefId) -> () {
desc { |tcx| "checking privacy in {}", describe_as_module(key.to_def_id(), tcx) }
desc { |tcx| "checking privacy in {}", describe_as_module(key, tcx) }
}

query check_mod_intrinsics(key: DefId) -> () {
query check_mod_intrinsics(key: LocalDefId) -> () {
desc { |tcx| "checking intrinsics in {}", describe_as_module(key, tcx) }
}

query check_mod_liveness(key: DefId) -> () {
query check_mod_liveness(key: LocalDefId) -> () {
desc { |tcx| "checking liveness of variables in {}", describe_as_module(key, tcx) }
}

query check_mod_impl_wf(key: DefId) -> () {
query check_mod_impl_wf(key: LocalDefId) -> () {
desc { |tcx| "checking that impls are well-formed in {}", describe_as_module(key, tcx) }
}

query collect_mod_item_types(key: DefId) -> () {
query collect_mod_item_types(key: LocalDefId) -> () {
desc { |tcx| "collecting item types in {}", describe_as_module(key, tcx) }
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/check_attr.rs
Expand Up @@ -12,7 +12,7 @@ use rustc_ast::ast::{Attribute, NestedMetaItem};
use rustc_ast::attr;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
use rustc_hir::{MethodKind, Target};
Expand Down Expand Up @@ -461,7 +461,7 @@ fn is_c_like_enum(item: &Item<'_>) -> bool {
}
}

fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir()
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/check_const.rs
Expand Up @@ -9,7 +9,7 @@

use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_middle::hir::map::Map;
use rustc_middle::ty::query::Providers;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl NonConstExpr {
}
}

fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let mut vis = CheckConstVisitor::new(tcx);
tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis.as_deep_visitor());
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/hir_id_validator.rs
Expand Up @@ -17,7 +17,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
let local_def_id = hir_map.local_def_id(*module_id);
hir_map.visit_item_likes_in_module(
local_def_id.to_def_id(),
local_def_id,
&mut OuterVisitor { hir_map, errors: &errors },
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/intrinsicck.rs
Expand Up @@ -2,7 +2,7 @@ use rustc_ast::ast::{FloatTy, InlineAsmTemplatePiece, IntTy, UintTy};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_index::vec::Idx;
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
Expand All @@ -14,7 +14,7 @@ use rustc_target::abi::{Pointer, VariantIdx};
use rustc_target::asm::{InlineAsmRegOrRegClass, InlineAsmType};
use rustc_target::spec::abi::Abi::RustIntrinsic;

fn check_mod_intrinsics(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_intrinsics(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(module_def_id, &mut ItemVisitor { tcx }.as_deep_visitor());
}

Expand Down
16 changes: 8 additions & 8 deletions src/librustc_passes/liveness.rs
Expand Up @@ -89,7 +89,7 @@ use rustc_data_structures::fx::FxIndexMap;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::def::*;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor};
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node};
use rustc_middle::hir::map::Map;
Expand Down Expand Up @@ -172,7 +172,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
}
}

fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(
module_def_id,
&mut IrMaps::new(tcx, module_def_id).as_deep_visitor(),
Expand Down Expand Up @@ -248,7 +248,7 @@ enum VarKind {

struct IrMaps<'tcx> {
tcx: TyCtxt<'tcx>,
body_owner: DefId,
body_owner: LocalDefId,
num_live_nodes: usize,
num_vars: usize,
live_node_map: HirIdMap<LiveNode>,
Expand All @@ -259,7 +259,7 @@ struct IrMaps<'tcx> {
}

impl IrMaps<'tcx> {
fn new(tcx: TyCtxt<'tcx>, body_owner: DefId) -> IrMaps<'tcx> {
fn new(tcx: TyCtxt<'tcx>, body_owner: LocalDefId) -> IrMaps<'tcx> {
IrMaps {
tcx,
body_owner,
Expand Down Expand Up @@ -349,7 +349,7 @@ fn visit_fn<'tcx>(

// swap in a new set of IR maps for this function body:
let def_id = ir.tcx.hir().local_def_id(id);
let mut fn_maps = IrMaps::new(ir.tcx, def_id.to_def_id());
let mut fn_maps = IrMaps::new(ir.tcx, def_id);

// Don't run unused pass for #[derive()]
if let FnKind::Method(..) = fk {
Expand Down Expand Up @@ -484,7 +484,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
}
ir.set_captures(expr.hir_id, call_caps);
let old_body_owner = ir.body_owner;
ir.body_owner = closure_def_id.to_def_id();
ir.body_owner = closure_def_id;
intravisit::walk_expr(ir, expr);
ir.body_owner = old_body_owner;
}
Expand Down Expand Up @@ -937,7 +937,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
for (&var_hir_id, upvar) in upvars.iter().rev() {
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: self.ir.body_owner.expect_local(),
closure_expr_id: self.ir.body_owner,
};
match self.tables.upvar_capture(upvar_id) {
ty::UpvarCapture::ByRef(_) => {
Expand Down Expand Up @@ -1614,7 +1614,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
let var = self.variable(var_hir_id, upvar.span);
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: self.ir.body_owner.expect_local(),
closure_expr_id: self.ir.body_owner,
};
match self.tables.upvar_capture(upvar_id) {
ty::UpvarCapture::ByValue => {}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/loops.rs
Expand Up @@ -2,7 +2,7 @@ use Context::*;

use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Destination, Movability, Node};
use rustc_middle::hir::map::Map;
Expand All @@ -29,7 +29,7 @@ struct CheckLoopVisitor<'a, 'hir> {
cx: Context,
}

fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(
module_def_id,
&mut CheckLoopVisitor { sess: &tcx.sess, hir_map: tcx.hir(), cx: Normal }.as_deep_visitor(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_passes/stability.rs
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Generics, HirId, Item, StructField, Variant};
use rustc_middle::hir::map::Map;
Expand Down Expand Up @@ -472,7 +472,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {

/// Cross-references the feature names of unstable APIs with enabled
/// features and possibly prints errors.
fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx }.as_deep_visitor());
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/mod.rs
Expand Up @@ -737,7 +737,7 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
tcx.hir().krate().par_visit_all_item_likes(&visit);
}

fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Expand Up @@ -55,7 +55,7 @@ struct OnlySelfBounds(bool);
///////////////////////////////////////////////////////////////////////////
// Main entry point

fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
tcx.hir().visit_item_likes_in_module(
module_def_id,
&mut CollectItemTypesVisitor { tcx }.as_deep_visitor(),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/impl_wf_check.rs
Expand Up @@ -14,7 +14,7 @@ use min_specialization::check_min_specialization;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::def_id::LocalDefId;
use rustc_hir::itemlikevisit::ItemLikeVisitor;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
Expand Down Expand Up @@ -59,11 +59,11 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
// but it's one that we must perform earlier than the rest of
// WfCheck.
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module).to_def_id());
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
}
}

fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: DefId) {
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
let min_specialization = tcx.features().min_specialization;
tcx.hir()
.visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx, min_specialization });
Expand Down

0 comments on commit a4e7b47

Please sign in to comment.