@@ -20,7 +20,7 @@ use hir::map as hir_map;
20
20
use hir:: def:: Def ;
21
21
use hir:: def_id:: { DefId , CrateNum } ;
22
22
use rustc_data_structures:: sync:: Lrc ;
23
- use ty:: { self , TyCtxt } ;
23
+ use ty:: { self , TyCtxt , GenericParamDefKind } ;
24
24
use ty:: query:: Providers ;
25
25
use middle:: privacy;
26
26
use session:: config;
@@ -29,19 +29,19 @@ use util::nodemap::{NodeSet, FxHashSet};
29
29
use rustc_target:: spec:: abi:: Abi ;
30
30
use syntax:: ast;
31
31
use syntax:: attr;
32
- use hir:: { self , GenericParamKind } ;
32
+ use hir;
33
33
use hir:: def_id:: LOCAL_CRATE ;
34
34
use hir:: intravisit:: { Visitor , NestedVisitorMap } ;
35
35
use hir:: itemlikevisit:: ItemLikeVisitor ;
36
36
use hir:: intravisit;
37
37
38
38
// Returns true if the given set of generics implies that the item it's
39
39
// associated with must be inlined.
40
- fn generics_require_inlining ( generics : & hir :: Generics ) -> bool {
40
+ fn generics_require_inlining ( generics : & ty :: Generics ) -> bool {
41
41
for param in & generics. params {
42
42
match param. kind {
43
- GenericParamKind :: Lifetime { .. } => { }
44
- GenericParamKind :: Type { .. } => return true ,
43
+ GenericParamDefKind :: Lifetime { .. } => { }
44
+ GenericParamDefKind :: Type { .. } => return true ,
45
45
}
46
46
}
47
47
false
@@ -50,14 +50,17 @@ fn generics_require_inlining(generics: &hir::Generics) -> bool {
50
50
// Returns true if the given item must be inlined because it may be
51
51
// monomorphized or it was marked with `#[inline]`. This will only return
52
52
// true for functions.
53
- fn item_might_be_inlined ( item : & hir:: Item , attrs : CodegenFnAttrs ) -> bool {
53
+ fn item_might_be_inlined ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
54
+ item : & hir:: Item ,
55
+ attrs : CodegenFnAttrs ) -> bool {
54
56
if attrs. requests_inline ( ) {
55
57
return true
56
58
}
57
59
58
60
match item. node {
59
- hir:: ItemImpl ( _, _, _, ref generics, ..) |
60
- hir:: ItemFn ( .., ref generics, _) => {
61
+ hir:: ItemImpl ( ..) |
62
+ hir:: ItemFn ( ..) => {
63
+ let generics = tcx. generics_of ( tcx. hir . local_def_id ( item. id ) ) ;
61
64
generics_require_inlining ( generics)
62
65
}
63
66
_ => false ,
@@ -68,14 +71,14 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
68
71
impl_item : & hir:: ImplItem ,
69
72
impl_src : DefId ) -> bool {
70
73
let codegen_fn_attrs = tcx. codegen_fn_attrs ( impl_item. hir_id . owner_def_id ( ) ) ;
71
- if codegen_fn_attrs . requests_inline ( ) ||
72
- generics_require_inlining ( & impl_item . generics ) {
74
+ let generics = tcx . generics_of ( tcx . hir . local_def_id ( impl_item . id ) ) ;
75
+ if codegen_fn_attrs . requests_inline ( ) || generics_require_inlining ( generics) {
73
76
return true
74
77
}
75
78
if let Some ( impl_node_id) = tcx. hir . as_local_node_id ( impl_src) {
76
79
match tcx. hir . find ( impl_node_id) {
77
80
Some ( hir_map:: NodeItem ( item) ) =>
78
- item_might_be_inlined ( & item, codegen_fn_attrs) ,
81
+ item_might_be_inlined ( tcx , & item, codegen_fn_attrs) ,
79
82
Some ( ..) | None =>
80
83
span_bug ! ( impl_item. span, "impl did is not an item" )
81
84
}
@@ -169,7 +172,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
169
172
Some ( hir_map:: NodeItem ( item) ) => {
170
173
match item. node {
171
174
hir:: ItemFn ( ..) =>
172
- item_might_be_inlined ( & item, self . tcx . codegen_fn_attrs ( def_id) ) ,
175
+ item_might_be_inlined ( self . tcx , & item, self . tcx . codegen_fn_attrs ( def_id) ) ,
173
176
_ => false ,
174
177
}
175
178
}
@@ -186,7 +189,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
186
189
hir:: ImplItemKind :: Const ( ..) => true ,
187
190
hir:: ImplItemKind :: Method ( ..) => {
188
191
let attrs = self . tcx . codegen_fn_attrs ( def_id) ;
189
- if generics_require_inlining ( & impl_item. generics ) ||
192
+ let generics = self . tcx . generics_of ( def_id) ;
193
+ if generics_require_inlining ( & generics) ||
190
194
attrs. requests_inline ( ) {
191
195
true
192
196
} else {
@@ -198,8 +202,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
198
202
// does too.
199
203
let impl_node_id = self . tcx . hir . as_local_node_id ( impl_did) . unwrap ( ) ;
200
204
match self . tcx . hir . expect_item ( impl_node_id) . node {
201
- hir:: ItemImpl ( _, _, _, ref generics, ..) => {
202
- generics_require_inlining ( generics)
205
+ hir:: ItemImpl ( ..) => {
206
+ let generics = self . tcx . generics_of ( impl_did) ;
207
+ generics_require_inlining ( & generics)
203
208
}
204
209
_ => false
205
210
}
@@ -257,7 +262,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
257
262
match item. node {
258
263
hir:: ItemFn ( .., body) => {
259
264
let def_id = self . tcx . hir . local_def_id ( item. id ) ;
260
- if item_might_be_inlined ( & item, self . tcx . codegen_fn_attrs ( def_id) ) {
265
+ if item_might_be_inlined ( self . tcx ,
266
+ & item,
267
+ self . tcx . codegen_fn_attrs ( def_id) ) {
261
268
self . visit_nested_body ( body) ;
262
269
}
263
270
}
0 commit comments