@@ -2302,10 +2302,19 @@ impl<'tcx> ty::Instance<'tcx> {
2302
2302
// FIXME(davidtwco,eddyb): A `ParamEnv` should be passed through to this function.
2303
2303
let ty = self . ty ( tcx, ty:: ParamEnv :: reveal_all ( ) ) ;
2304
2304
match ty. kind {
2305
- ty:: FnDef ( ..) |
2306
- // Shims currently have type FnPtr. Not sure this should remain.
2307
- ty:: FnPtr ( _) => {
2308
- let mut sig = ty. fn_sig ( tcx) ;
2305
+ ty:: FnDef ( ..) => {
2306
+ // HACK(davidtwco,eddyb): This is a workaround for polymorphization considering
2307
+ // parameters unused if they show up in the signature, but not in the `mir::Body`
2308
+ // (i.e. due to being inside a projection that got normalized, see
2309
+ // `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
2310
+ // track of a polymorphization `ParamEnv` to allow normalizing later.
2311
+ let mut sig = match ty. kind {
2312
+ ty:: FnDef ( def_id, substs) => tcx
2313
+ . normalize_erasing_regions ( tcx. param_env ( def_id) , tcx. fn_sig ( def_id) )
2314
+ . subst ( tcx, substs) ,
2315
+ _ => unreachable ! ( ) ,
2316
+ } ;
2317
+
2309
2318
if let ty:: InstanceDef :: VtableShim ( ..) = self . def {
2310
2319
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
2311
2320
sig = sig. map_bound ( |mut sig| {
@@ -2321,13 +2330,15 @@ impl<'tcx> ty::Instance<'tcx> {
2321
2330
let sig = substs. as_closure ( ) . sig ( ) ;
2322
2331
2323
2332
let env_ty = tcx. closure_env_ty ( def_id, substs) . unwrap ( ) ;
2324
- sig. map_bound ( |sig| tcx. mk_fn_sig (
2325
- iter:: once ( env_ty. skip_binder ( ) ) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
2326
- sig. output ( ) ,
2327
- sig. c_variadic ,
2328
- sig. unsafety ,
2329
- sig. abi
2330
- ) )
2333
+ sig. map_bound ( |sig| {
2334
+ tcx. mk_fn_sig (
2335
+ iter:: once ( env_ty. skip_binder ( ) ) . chain ( sig. inputs ( ) . iter ( ) . cloned ( ) ) ,
2336
+ sig. output ( ) ,
2337
+ sig. c_variadic ,
2338
+ sig. unsafety ,
2339
+ sig. abi ,
2340
+ )
2341
+ } )
2331
2342
}
2332
2343
ty:: Generator ( _, substs, _) => {
2333
2344
let sig = substs. as_generator ( ) . poly_sig ( ) ;
@@ -2343,22 +2354,20 @@ impl<'tcx> ty::Instance<'tcx> {
2343
2354
sig. map_bound ( |sig| {
2344
2355
let state_did = tcx. require_lang_item ( GeneratorStateLangItem , None ) ;
2345
2356
let state_adt_ref = tcx. adt_def ( state_did) ;
2346
- let state_substs = tcx. intern_substs ( & [
2347
- sig. yield_ty . into ( ) ,
2348
- sig. return_ty . into ( ) ,
2349
- ] ) ;
2357
+ let state_substs =
2358
+ tcx. intern_substs ( & [ sig. yield_ty . into ( ) , sig. return_ty . into ( ) ] ) ;
2350
2359
let ret_ty = tcx. mk_adt ( state_adt_ref, state_substs) ;
2351
2360
2352
2361
tcx. mk_fn_sig (
2353
2362
[ env_ty, sig. resume_ty ] . iter ( ) ,
2354
2363
& ret_ty,
2355
2364
false ,
2356
2365
hir:: Unsafety :: Normal ,
2357
- rustc_target:: spec:: abi:: Abi :: Rust
2366
+ rustc_target:: spec:: abi:: Abi :: Rust ,
2358
2367
)
2359
2368
} )
2360
2369
}
2361
- _ => bug ! ( "unexpected type {:?} in Instance::fn_sig" , ty)
2370
+ _ => bug ! ( "unexpected type {:?} in Instance::fn_sig" , ty) ,
2362
2371
}
2363
2372
}
2364
2373
}
0 commit comments