Skip to content

Commit 283de4f

Browse files
committed
Accept LocalDefId as argument for mir_build::lint::check
1 parent 58ba925 commit 283de4f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/librustc_mir_build/build/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> {
181181
build::construct_const(cx, body_id, return_ty, return_ty_span)
182182
};
183183

184-
lints::check(tcx, &body, def_id.to_def_id());
184+
lints::check(tcx, &body, def_id);
185185

186186
// The borrow checker will replace all the regions here with its own
187187
// inference variables. There's no point having non-erased regions here.

src/librustc_mir_build/lints.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::graph::iterate::{
22
ControlFlow, NodeStatus, TriColorDepthFirstSearch, TriColorVisitor,
33
};
4-
use rustc_hir::def_id::DefId;
4+
use rustc_hir::def_id::LocalDefId;
55
use rustc_hir::intravisit::FnKind;
66
use rustc_middle::hir::map::blocks::FnLikeNode;
77
use rustc_middle::mir::{BasicBlock, Body, Operand, TerminatorKind};
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
1010
use rustc_session::lint::builtin::UNCONDITIONAL_RECURSION;
1111
use rustc_span::Span;
1212

13-
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
14-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
13+
crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: LocalDefId) {
14+
let hir_id = tcx.hir().as_local_hir_id(def_id);
1515

1616
if let Some(fn_like_node) = FnLikeNode::from_node(tcx.hir().get(hir_id)) {
1717
if let FnKind::Closure(_) = fn_like_node.kind() {
@@ -20,12 +20,12 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
2020
}
2121

2222
// If this is trait/impl method, extract the trait's substs.
23-
let trait_substs = match tcx.opt_associated_item(def_id) {
23+
let trait_substs = match tcx.opt_associated_item(def_id.to_def_id()) {
2424
Some(AssocItem {
2525
container: AssocItemContainer::TraitContainer(trait_def_id), ..
2626
}) => {
2727
let trait_substs_count = tcx.generics_of(trait_def_id).count();
28-
&InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]
28+
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
2929
}
3030
_ => &[],
3131
};
@@ -37,7 +37,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
3737

3838
vis.reachable_recursive_calls.sort();
3939

40-
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
40+
let hir_id = tcx.hir().as_local_hir_id(def_id);
4141
let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span(hir_id));
4242
tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| {
4343
let mut db = lint.build("function cannot return without recursing");
@@ -57,7 +57,7 @@ struct NonRecursive;
5757
struct Search<'mir, 'tcx> {
5858
tcx: TyCtxt<'tcx>,
5959
body: &'mir Body<'tcx>,
60-
def_id: DefId,
60+
def_id: LocalDefId,
6161
trait_substs: &'tcx [GenericArg<'tcx>],
6262

6363
reachable_recursive_calls: Vec<Span>,
@@ -84,7 +84,8 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {
8484
// calling into an entirely different method (for example, a call from the default
8585
// method in the trait to `<A as Trait<B>>::method`, where `A` and/or `B` are
8686
// specific types).
87-
return call_fn_id == def_id && &call_substs[..trait_substs.len()] == trait_substs;
87+
return call_fn_id == def_id.to_def_id()
88+
&& &call_substs[..trait_substs.len()] == trait_substs;
8889
}
8990

9091
false

0 commit comments

Comments
 (0)