Skip to content

Commit a4e7b47

Browse files
committed
use LocalDefId in module checking
1 parent d8ed1b0 commit a4e7b47

File tree

12 files changed

+39
-39
lines changed

12 files changed

+39
-39
lines changed

src/librustc_middle/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ impl<'hir> Map<'hir> {
451451
}
452452
}
453453

454-
pub fn visit_item_likes_in_module<V>(&self, module: DefId, visitor: &mut V)
454+
pub fn visit_item_likes_in_module<V>(&self, module: LocalDefId, visitor: &mut V)
455455
where
456456
V: ItemLikeVisitor<'hir>,
457457
{
458-
let module = self.tcx.hir_module_items(module.expect_local());
458+
let module = self.tcx.hir_module_items(module);
459459

460460
for id in &module.items {
461461
visitor.visit_item(self.expect_item(*id));

src/librustc_middle/query/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ use rustc_query_system::query::QueryDescription;
1515
use rustc_span::symbol::Symbol;
1616
use std::borrow::Cow;
1717

18-
fn describe_as_module(def_id: DefId, tcx: TyCtxt<'_>) -> String {
18+
fn describe_as_module(def_id: LocalDefId, tcx: TyCtxt<'_>) -> String {
1919
if def_id.is_top_level_module() {
2020
"top-level module".to_string()
2121
} else {
22-
format!("module `{}`", tcx.def_path_str(def_id))
22+
format!("module `{}`", tcx.def_path_str(def_id.to_def_id()))
2323
}
2424
}
2525

@@ -473,49 +473,49 @@ rustc_queries! {
473473

474474
Other {
475475
query lint_mod(key: LocalDefId) -> () {
476-
desc { |tcx| "linting {}", describe_as_module(key.to_def_id(), tcx) }
476+
desc { |tcx| "linting {}", describe_as_module(key, tcx) }
477477
}
478478

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

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

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

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

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

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

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

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

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

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

src/librustc_passes/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::ast::{Attribute, NestedMetaItem};
1212
use rustc_ast::attr;
1313
use rustc_errors::struct_span_err;
1414
use rustc_hir as hir;
15-
use rustc_hir::def_id::DefId;
15+
use rustc_hir::def_id::LocalDefId;
1616
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1717
use rustc_hir::{self, HirId, Item, ItemKind, TraitItem};
1818
use rustc_hir::{MethodKind, Target};
@@ -461,7 +461,7 @@ fn is_c_like_enum(item: &Item<'_>) -> bool {
461461
}
462462
}
463463

464-
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: DefId) {
464+
fn check_mod_attrs(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
465465
tcx.hir()
466466
.visit_item_likes_in_module(module_def_id, &mut CheckAttrVisitor { tcx }.as_deep_visitor());
467467
}

src/librustc_passes/check_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
use rustc_errors::struct_span_err;
1111
use rustc_hir as hir;
12-
use rustc_hir::def_id::DefId;
12+
use rustc_hir::def_id::LocalDefId;
1313
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1414
use rustc_middle::hir::map::Map;
1515
use rustc_middle::ty::query::Providers;
@@ -62,7 +62,7 @@ impl NonConstExpr {
6262
}
6363
}
6464

65-
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: DefId) {
65+
fn check_mod_const_bodies(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
6666
let mut vis = CheckConstVisitor::new(tcx);
6767
tcx.hir().visit_item_likes_in_module(module_def_id, &mut vis.as_deep_visitor());
6868
}

src/librustc_passes/hir_id_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
1717
par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| {
1818
let local_def_id = hir_map.local_def_id(*module_id);
1919
hir_map.visit_item_likes_in_module(
20-
local_def_id.to_def_id(),
20+
local_def_id,
2121
&mut OuterVisitor { hir_map, errors: &errors },
2222
);
2323
});

src/librustc_passes/intrinsicck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast::ast::{FloatTy, InlineAsmTemplatePiece, IntTy, UintTy};
22
use rustc_errors::struct_span_err;
33
use rustc_hir as hir;
44
use rustc_hir::def::{DefKind, Res};
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::{DefId, LocalDefId};
66
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
77
use rustc_index::vec::Idx;
88
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
@@ -14,7 +14,7 @@ use rustc_target::abi::{Pointer, VariantIdx};
1414
use rustc_target::asm::{InlineAsmRegOrRegClass, InlineAsmType};
1515
use rustc_target::spec::abi::Abi::RustIntrinsic;
1616

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

src/librustc_passes/liveness.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ use rustc_data_structures::fx::FxIndexMap;
8989
use rustc_errors::Applicability;
9090
use rustc_hir as hir;
9191
use rustc_hir::def::*;
92-
use rustc_hir::def_id::{DefId, LocalDefId};
92+
use rustc_hir::def_id::LocalDefId;
9393
use rustc_hir::intravisit::{self, FnKind, NestedVisitorMap, Visitor};
9494
use rustc_hir::{Expr, HirId, HirIdMap, HirIdSet, Node};
9595
use rustc_middle::hir::map::Map;
@@ -172,7 +172,7 @@ impl<'tcx> Visitor<'tcx> for IrMaps<'tcx> {
172172
}
173173
}
174174

175-
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: DefId) {
175+
fn check_mod_liveness(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
176176
tcx.hir().visit_item_likes_in_module(
177177
module_def_id,
178178
&mut IrMaps::new(tcx, module_def_id).as_deep_visitor(),
@@ -248,7 +248,7 @@ enum VarKind {
248248

249249
struct IrMaps<'tcx> {
250250
tcx: TyCtxt<'tcx>,
251-
body_owner: DefId,
251+
body_owner: LocalDefId,
252252
num_live_nodes: usize,
253253
num_vars: usize,
254254
live_node_map: HirIdMap<LiveNode>,
@@ -259,7 +259,7 @@ struct IrMaps<'tcx> {
259259
}
260260

261261
impl IrMaps<'tcx> {
262-
fn new(tcx: TyCtxt<'tcx>, body_owner: DefId) -> IrMaps<'tcx> {
262+
fn new(tcx: TyCtxt<'tcx>, body_owner: LocalDefId) -> IrMaps<'tcx> {
263263
IrMaps {
264264
tcx,
265265
body_owner,
@@ -349,7 +349,7 @@ fn visit_fn<'tcx>(
349349

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

354354
// Don't run unused pass for #[derive()]
355355
if let FnKind::Method(..) = fk {
@@ -484,7 +484,7 @@ fn visit_expr<'tcx>(ir: &mut IrMaps<'tcx>, expr: &'tcx Expr<'tcx>) {
484484
}
485485
ir.set_captures(expr.hir_id, call_caps);
486486
let old_body_owner = ir.body_owner;
487-
ir.body_owner = closure_def_id.to_def_id();
487+
ir.body_owner = closure_def_id;
488488
intravisit::walk_expr(ir, expr);
489489
ir.body_owner = old_body_owner;
490490
}
@@ -937,7 +937,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
937937
for (&var_hir_id, upvar) in upvars.iter().rev() {
938938
let upvar_id = ty::UpvarId {
939939
var_path: ty::UpvarPath { hir_id: var_hir_id },
940-
closure_expr_id: self.ir.body_owner.expect_local(),
940+
closure_expr_id: self.ir.body_owner,
941941
};
942942
match self.tables.upvar_capture(upvar_id) {
943943
ty::UpvarCapture::ByRef(_) => {
@@ -1614,7 +1614,7 @@ impl<'tcx> Liveness<'_, 'tcx> {
16141614
let var = self.variable(var_hir_id, upvar.span);
16151615
let upvar_id = ty::UpvarId {
16161616
var_path: ty::UpvarPath { hir_id: var_hir_id },
1617-
closure_expr_id: self.ir.body_owner.expect_local(),
1617+
closure_expr_id: self.ir.body_owner,
16181618
};
16191619
match self.tables.upvar_capture(upvar_id) {
16201620
ty::UpvarCapture::ByValue => {}

src/librustc_passes/loops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use Context::*;
22

33
use rustc_errors::{struct_span_err, Applicability};
44
use rustc_hir as hir;
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::LocalDefId;
66
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
77
use rustc_hir::{Destination, Movability, Node};
88
use rustc_middle::hir::map::Map;
@@ -29,7 +29,7 @@ struct CheckLoopVisitor<'a, 'hir> {
2929
cx: Context,
3030
}
3131

32-
fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: DefId) {
32+
fn check_mod_loops(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
3333
tcx.hir().visit_item_likes_in_module(
3434
module_def_id,
3535
&mut CheckLoopVisitor { sess: &tcx.sess, hir_map: tcx.hir(), cx: Normal }.as_deep_visitor(),

src/librustc_passes/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
77
use rustc_errors::struct_span_err;
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
10-
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
10+
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1111
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1212
use rustc_hir::{Generics, HirId, Item, StructField, Variant};
1313
use rustc_middle::hir::map::Map;
@@ -472,7 +472,7 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
472472

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

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ pub fn check_wf_new(tcx: TyCtxt<'_>) {
737737
tcx.hir().krate().par_visit_all_item_likes(&visit);
738738
}
739739

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

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct OnlySelfBounds(bool);
5555
///////////////////////////////////////////////////////////////////////////
5656
// Main entry point
5757

58-
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: DefId) {
58+
fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
5959
tcx.hir().visit_item_likes_in_module(
6060
module_def_id,
6161
&mut CollectItemTypesVisitor { tcx }.as_deep_visitor(),

src/librustc_typeck/impl_wf_check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use min_specialization::check_min_specialization;
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_errors::struct_span_err;
1616
use rustc_hir as hir;
17-
use rustc_hir::def_id::{DefId, LocalDefId};
17+
use rustc_hir::def_id::LocalDefId;
1818
use rustc_hir::itemlikevisit::ItemLikeVisitor;
1919
use rustc_middle::ty::query::Providers;
2020
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
@@ -59,11 +59,11 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
5959
// but it's one that we must perform earlier than the rest of
6060
// WfCheck.
6161
for &module in tcx.hir().krate().modules.keys() {
62-
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module).to_def_id());
62+
tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module));
6363
}
6464
}
6565

66-
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: DefId) {
66+
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
6767
let min_specialization = tcx.features().min_specialization;
6868
tcx.hir()
6969
.visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx, min_specialization });

0 commit comments

Comments
 (0)