1
1
use rustc_data_structures:: graph:: iterate:: {
2
2
ControlFlow , NodeStatus , TriColorDepthFirstSearch , TriColorVisitor ,
3
3
} ;
4
- use rustc_hir:: def_id:: DefId ;
4
+ use rustc_hir:: def_id:: LocalDefId ;
5
5
use rustc_hir:: intravisit:: FnKind ;
6
6
use rustc_middle:: hir:: map:: blocks:: FnLikeNode ;
7
7
use rustc_middle:: mir:: { BasicBlock , Body , Operand , TerminatorKind } ;
@@ -10,8 +10,8 @@ use rustc_middle::ty::{self, AssocItem, AssocItemContainer, Instance, TyCtxt};
10
10
use rustc_session:: lint:: builtin:: UNCONDITIONAL_RECURSION ;
11
11
use rustc_span:: Span ;
12
12
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) ;
15
15
16
16
if let Some ( fn_like_node) = FnLikeNode :: from_node ( tcx. hir ( ) . get ( hir_id) ) {
17
17
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) {
20
20
}
21
21
22
22
// 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 ( ) ) {
24
24
Some ( AssocItem {
25
25
container : AssocItemContainer :: TraitContainer ( trait_def_id) , ..
26
26
} ) => {
27
27
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]
29
29
}
30
30
_ => & [ ] ,
31
31
} ;
@@ -37,7 +37,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId) {
37
37
38
38
vis. reachable_recursive_calls . sort ( ) ;
39
39
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) ;
41
41
let sp = tcx. sess . source_map ( ) . guess_head_span ( tcx. hir ( ) . span ( hir_id) ) ;
42
42
tcx. struct_span_lint_hir ( UNCONDITIONAL_RECURSION , hir_id, sp, |lint| {
43
43
let mut db = lint. build ( "function cannot return without recursing" ) ;
@@ -57,7 +57,7 @@ struct NonRecursive;
57
57
struct Search < ' mir , ' tcx > {
58
58
tcx : TyCtxt < ' tcx > ,
59
59
body : & ' mir Body < ' tcx > ,
60
- def_id : DefId ,
60
+ def_id : LocalDefId ,
61
61
trait_substs : & ' tcx [ GenericArg < ' tcx > ] ,
62
62
63
63
reachable_recursive_calls : Vec < Span > ,
@@ -84,7 +84,8 @@ impl<'mir, 'tcx> Search<'mir, 'tcx> {
84
84
// calling into an entirely different method (for example, a call from the default
85
85
// method in the trait to `<A as Trait<B>>::method`, where `A` and/or `B` are
86
86
// 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;
88
89
}
89
90
90
91
false
0 commit comments