@@ -7,6 +7,7 @@ use rustc_index::Idx;
7
7
use rustc_middle:: middle:: codegen_fn_attrs:: { CodegenFnAttrFlags , CodegenFnAttrs } ;
8
8
use rustc_middle:: mir:: visit:: * ;
9
9
use rustc_middle:: mir:: * ;
10
+ use rustc_middle:: ty:: TypeVisitableExt ;
10
11
use rustc_middle:: ty:: { self , Instance , InstanceDef , ParamEnv , Ty , TyCtxt } ;
11
12
use rustc_session:: config:: OptLevel ;
12
13
use rustc_span:: { hygiene:: ExpnKind , ExpnData , LocalExpnId , Span } ;
@@ -168,7 +169,7 @@ impl<'tcx> Inliner<'tcx> {
168
169
let callee_attrs = self . tcx . codegen_fn_attrs ( callsite. callee . def_id ( ) ) ;
169
170
self . check_codegen_attributes ( callsite, callee_attrs) ?;
170
171
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 ) ? ;
172
173
self . check_mir_body ( callsite, callee_body, callee_attrs) ?;
173
174
174
175
if !self . tcx . consider_optimizing ( || {
@@ -1124,3 +1125,27 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
1124
1125
}
1125
1126
}
1126
1127
}
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