File tree Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Expand file tree Collapse file tree 2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -69,9 +69,7 @@ impl<'tcx> CastTy<'tcx> {
69
69
Some ( CastTy :: Int ( IntTy :: CEnum ) ) ,
70
70
ty:: TyRawPtr ( ref mt) => Some ( CastTy :: Ptr ( mt) ) ,
71
71
ty:: TyRef ( _, ref mt) => Some ( CastTy :: RPtr ( mt) ) ,
72
- // FIXME: Treating TyFnDef as a pointer here is a bit dubious;
73
- // we should be coercing the operand to an actual pointer.
74
- ty:: TyFnDef ( ..) | ty:: TyFnPtr ( ..) => Some ( CastTy :: FnPtr ) ,
72
+ ty:: TyFnPtr ( ..) => Some ( CastTy :: FnPtr ) ,
75
73
_ => None ,
76
74
}
77
75
}
Original file line number Diff line number Diff line change @@ -235,6 +235,20 @@ impl<'tcx> CastCheck<'tcx> {
235
235
let ( t_from, t_cast) = match ( CastTy :: from_ty ( self . expr_ty ) ,
236
236
CastTy :: from_ty ( self . cast_ty ) ) {
237
237
( Some ( t_from) , Some ( t_cast) ) => ( t_from, t_cast) ,
238
+ // Function item types may need to be reified before casts.
239
+ ( None , Some ( t_cast) ) => {
240
+ if let ty:: TyFnDef ( _, _, f) = self . expr_ty . sty {
241
+ // Attempt a coercion to a fn pointer type.
242
+ let res = coercion:: mk_assignty ( fcx, & self . expr ,
243
+ self . expr_ty , fcx. tcx ( ) . mk_ty ( ty:: TyFnPtr ( f) ) ) ;
244
+ if !res. is_ok ( ) {
245
+ return Err ( CastError :: NonScalar ) ;
246
+ }
247
+ ( FnPtr , t_cast)
248
+ } else {
249
+ return Err ( CastError :: NonScalar ) ;
250
+ }
251
+ }
238
252
_ => {
239
253
return Err ( CastError :: NonScalar )
240
254
}
You can’t perform that action at this time.
0 commit comments