@@ -20,7 +20,7 @@ use hir::map as hir_map;
2020use hir:: def:: Def ;
2121use hir:: def_id:: { DefId , CrateNum } ;
2222use rustc_data_structures:: sync:: Lrc ;
23- use ty:: { self , TyCtxt } ;
23+ use ty:: { self , TyCtxt , GenericParamDefKind } ;
2424use ty:: query:: Providers ;
2525use middle:: privacy;
2626use session:: config;
@@ -29,19 +29,19 @@ use util::nodemap::{NodeSet, FxHashSet};
2929use rustc_target:: spec:: abi:: Abi ;
3030use syntax:: ast;
3131use syntax:: attr;
32- use hir:: { self , GenericParamKind } ;
32+ use hir;
3333use hir:: def_id:: LOCAL_CRATE ;
3434use hir:: intravisit:: { Visitor , NestedVisitorMap } ;
3535use hir:: itemlikevisit:: ItemLikeVisitor ;
3636use hir:: intravisit;
3737
3838// Returns true if the given set of generics implies that the item it's
3939// associated with must be inlined.
40- fn generics_require_inlining ( generics : & hir :: Generics ) -> bool {
40+ fn generics_require_inlining ( generics : & ty :: Generics ) -> bool {
4141 for param in & generics. params {
4242 match param. kind {
43- GenericParamKind :: Lifetime { .. } => { }
44- GenericParamKind :: Type { .. } => return true ,
43+ GenericParamDefKind :: Lifetime { .. } => { }
44+ GenericParamDefKind :: Type { .. } => return true ,
4545 }
4646 }
4747 false
@@ -50,14 +50,17 @@ fn generics_require_inlining(generics: &hir::Generics) -> bool {
5050// Returns true if the given item must be inlined because it may be
5151// monomorphized or it was marked with `#[inline]`. This will only return
5252// 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 {
5456 if attrs. requests_inline ( ) {
5557 return true
5658 }
5759
5860 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 ) ) ;
6164 generics_require_inlining ( generics)
6265 }
6366 _ => false ,
@@ -68,14 +71,14 @@ fn method_might_be_inlined<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6871 impl_item : & hir:: ImplItem ,
6972 impl_src : DefId ) -> bool {
7073 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) {
7376 return true
7477 }
7578 if let Some ( impl_node_id) = tcx. hir . as_local_node_id ( impl_src) {
7679 match tcx. hir . find ( impl_node_id) {
7780 Some ( hir_map:: NodeItem ( item) ) =>
78- item_might_be_inlined ( & item, codegen_fn_attrs) ,
81+ item_might_be_inlined ( tcx , & item, codegen_fn_attrs) ,
7982 Some ( ..) | None =>
8083 span_bug ! ( impl_item. span, "impl did is not an item" )
8184 }
@@ -169,7 +172,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
169172 Some ( hir_map:: NodeItem ( item) ) => {
170173 match item. node {
171174 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) ) ,
173176 _ => false ,
174177 }
175178 }
@@ -186,7 +189,8 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
186189 hir:: ImplItemKind :: Const ( ..) => true ,
187190 hir:: ImplItemKind :: Method ( ..) => {
188191 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) ||
190194 attrs. requests_inline ( ) {
191195 true
192196 } else {
@@ -198,8 +202,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
198202 // does too.
199203 let impl_node_id = self . tcx . hir . as_local_node_id ( impl_did) . unwrap ( ) ;
200204 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)
203208 }
204209 _ => false
205210 }
@@ -257,7 +262,9 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
257262 match item. node {
258263 hir:: ItemFn ( .., body) => {
259264 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) ) {
261268 self . visit_nested_body ( body) ;
262269 }
263270 }
0 commit comments