@@ -77,6 +77,42 @@ impl<'tcx> InstanceDef<'tcx> {
77
77
pub fn attrs < ' a > ( & self , tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> ty:: Attributes < ' tcx > {
78
78
tcx. get_attrs ( self . def_id ( ) )
79
79
}
80
+
81
+ pub fn is_inline < ' a > (
82
+ & self ,
83
+ tcx : TyCtxt < ' a , ' tcx , ' tcx >
84
+ ) -> bool {
85
+ use hir:: map:: DefPathData ;
86
+ let def_id = match * self {
87
+ ty:: InstanceDef :: Item ( def_id) => def_id,
88
+ ty:: InstanceDef :: DropGlue ( _, Some ( _) ) => return false ,
89
+ _ => return true
90
+ } ;
91
+ match tcx. def_key ( def_id) . disambiguated_data . data {
92
+ DefPathData :: StructCtor |
93
+ DefPathData :: EnumVariant ( ..) |
94
+ DefPathData :: ClosureExpr => true ,
95
+ _ => false
96
+ }
97
+ }
98
+
99
+ pub fn requires_local < ' a > (
100
+ & self ,
101
+ tcx : TyCtxt < ' a , ' tcx , ' tcx >
102
+ ) -> bool {
103
+ use syntax:: attr:: requests_inline;
104
+ if self . is_inline ( tcx) {
105
+ return true
106
+ }
107
+ if let ty:: InstanceDef :: DropGlue ( ..) = * self {
108
+ // Drop glue wants to be instantiated at every translation
109
+ // unit, but without an #[inline] hint. We should make this
110
+ // available to normal end-users.
111
+ return true
112
+ }
113
+ requests_inline ( & self . attrs ( tcx) [ ..] ) ||
114
+ tcx. is_const_fn ( self . def_id ( ) )
115
+ }
80
116
}
81
117
82
118
impl < ' tcx > fmt:: Display for Instance < ' tcx > {
0 commit comments