@@ -7,6 +7,7 @@ use rustc_index::Idx;
77use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
88use rustc_middle:: mir:: visit:: * ;
99use rustc_middle:: mir:: * ;
10+ use rustc_middle:: ty:: TypeVisitableExt ;
1011use rustc_middle:: ty:: { self , Instance , InstanceDef , ParamEnv , Ty , TyCtxt } ;
1112use rustc_session:: config:: OptLevel ;
1213use rustc_span:: { hygiene:: ExpnKind , ExpnData , LocalExpnId , Span } ;
@@ -168,7 +169,7 @@ impl<'tcx> Inliner<'tcx> {
168169 let callee_attrs = self . tcx . codegen_fn_attrs ( callsite. callee . def_id ( ) ) ;
169170 self . check_codegen_attributes ( callsite, callee_attrs) ?;
170171 self . check_mir_is_available ( caller_body, & callsite. callee ) ?;
171- let callee_body = self . tcx . instance_mir ( callsite. callee . def ) ;
172+ let callee_body = try_instance_mir ( self . tcx , callsite. callee . def ) ? ;
172173 self . check_mir_body ( callsite, callee_body, callee_attrs) ?;
173174
174175 if !self . tcx . consider_optimizing ( || {
@@ -1124,3 +1125,27 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
11241125 }
11251126 }
11261127}
1128+
1129+ #[ instrument( skip( tcx) , level = "debug" ) ]
1130+ fn try_instance_mir < ' tcx > (
1131+ tcx : TyCtxt < ' tcx > ,
1132+ instance : InstanceDef < ' tcx > ,
1133+ ) -> Result < & ' tcx Body < ' tcx > , & ' static str > {
1134+ match instance {
1135+ ty:: InstanceDef :: DropGlue ( _, Some ( ty) ) => match ty. kind ( ) {
1136+ ty:: Adt ( def, substs) => {
1137+ let fields = def. all_fields ( ) ;
1138+ for field in fields {
1139+ let field_ty = field. ty ( tcx, substs) ;
1140+ if field_ty. has_param ( ) && field_ty. has_projections ( ) {
1141+ return Err ( "cannot build drop shim for polymorphic type" ) ;
1142+ }
1143+ }
1144+
1145+ Ok ( tcx. instance_mir ( instance) )
1146+ }
1147+ _ => Ok ( tcx. instance_mir ( instance) ) ,
1148+ } ,
1149+ _ => Ok ( tcx. instance_mir ( instance) ) ,
1150+ }
1151+ }
0 commit comments