@@ -188,18 +188,27 @@ pub enum FullDefKind<Body> {
188
188
param_env : ParamEnv ,
189
189
#[ value( s. base( ) . tcx. adt_def( s. owner_id( ) ) . sinto( s) ) ]
190
190
def : AdtDef ,
191
+ /// MIR body of the builtin `drop` impl.
192
+ #[ value( drop_glue_shim( s. base( ) . tcx, s. owner_id( ) ) . and_then( |body| Body :: from_mir( s, body) ) ) ]
193
+ drop_glue : Option < Body > ,
191
194
} ,
192
195
Union {
193
196
#[ value( get_param_env( s, s. owner_id( ) ) ) ]
194
197
param_env : ParamEnv ,
195
198
#[ value( s. base( ) . tcx. adt_def( s. owner_id( ) ) . sinto( s) ) ]
196
199
def : AdtDef ,
200
+ /// MIR body of the builtin `drop` impl.
201
+ #[ value( drop_glue_shim( s. base( ) . tcx, s. owner_id( ) ) . and_then( |body| Body :: from_mir( s, body) ) ) ]
202
+ drop_glue : Option < Body > ,
197
203
} ,
198
204
Enum {
199
205
#[ value( get_param_env( s, s. owner_id( ) ) ) ]
200
206
param_env : ParamEnv ,
201
207
#[ value( s. base( ) . tcx. adt_def( s. owner_id( ) ) . sinto( s) ) ]
202
208
def : AdtDef ,
209
+ /// MIR body of the builtin `drop` impl.
210
+ #[ value( drop_glue_shim( s. base( ) . tcx, s. owner_id( ) ) . and_then( |body| Body :: from_mir( s, body) ) ) ]
211
+ drop_glue : Option < Body > ,
203
212
} ,
204
213
/// Type alias: `type Foo = Bar;`
205
214
TyAlias {
@@ -359,6 +368,9 @@ pub enum FullDefKind<Body> {
359
368
opt_body. and_then( |body| Body :: from_mir( s, body) )
360
369
} ) ]
361
370
once_shim : Option < Body > ,
371
+ /// MIR body of the builtin `drop` impl.
372
+ #[ value( drop_glue_shim( s. base( ) . tcx, s. owner_id( ) ) . and_then( |body| Body :: from_mir( s, body) ) ) ]
373
+ drop_glue : Option < Body > ,
362
374
} ,
363
375
364
376
// Constants
@@ -947,6 +959,20 @@ fn closure_once_shim<'tcx>(
947
959
Some ( mir)
948
960
}
949
961
962
+ #[ cfg( feature = "rustc" ) ]
963
+ fn drop_glue_shim < ' tcx > ( tcx : ty:: TyCtxt < ' tcx > , def_id : RDefId ) -> Option < mir:: Body < ' tcx > > {
964
+ let drop_in_place = tcx. require_lang_item ( rustc_hir:: LangItem :: DropInPlace , None ) ;
965
+ if !tcx. generics_of ( def_id) . is_empty ( ) {
966
+ // Hack: layout code panics if it can't fully normalize types, which can happen e.g. with a
967
+ // trait associated type. For now we only translate the glue for monomorphic types.
968
+ return None ;
969
+ }
970
+ let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
971
+ let instance_kind = ty:: InstanceKind :: DropGlue ( drop_in_place, Some ( ty) ) ;
972
+ let mir = tcx. instance_mir ( instance_kind) . clone ( ) ;
973
+ Some ( mir)
974
+ }
975
+
950
976
#[ cfg( feature = "rustc" ) ]
951
977
fn get_param_env < ' tcx , S : BaseState < ' tcx > > ( s : & S , def_id : RDefId ) -> ParamEnv {
952
978
let tcx = s. base ( ) . tcx ;
0 commit comments