use LocalDefId in module checking
This commit is contained in:
parent
d8ed1b03c2
commit
a4e7b47984
@ -451,11 +451,11 @@ pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
|
||||
}
|
||||
}
|
||||
|
||||
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));
|
||||
|
@ -15,11 +15,11 @@
|
||||
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()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,49 +473,49 @@ fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
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};
|
||||
@ -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());
|
||||
}
|
||||
|
@ -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;
|
||||
@ -62,7 +62,7 @@ fn required_feature_gates(self) -> Option<&'static [Symbol]> {
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -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 },
|
||||
);
|
||||
});
|
||||
|
@ -2,7 +2,7 @@
|
||||
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};
|
||||
@ -14,7 +14,7 @@
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@
|
||||
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;
|
||||
@ -172,7 +172,7 @@ fn visit_arm(&mut self, a: &'tcx hir::Arm<'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(),
|
||||
@ -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>,
|
||||
@ -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,
|
||||
@ -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 {
|
||||
@ -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;
|
||||
}
|
||||
@ -937,7 +937,7 @@ fn compute(
|
||||
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(_) => {
|
||||
@ -1614,7 +1614,7 @@ fn warn_about_unused_upvars(&self, entry_ln: LiveNode) {
|
||||
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 => {}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
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;
|
||||
@ -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(),
|
||||
|
@ -7,7 +7,7 @@
|
||||
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;
|
||||
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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 });
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// 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(),
|
||||
|
@ -14,7 +14,7 @@
|
||||
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};
|
||||
@ -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 });
|
||||
|
Loading…
Reference in New Issue
Block a user