@@ -1978,19 +1978,59 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1978
1978
1979
1979
match cast_kind {
1980
1980
CastKind :: PointerCoercion ( PointerCoercion :: ReifyFnPointer ) => {
1981
- let fn_sig = op. ty ( body, tcx) . fn_sig ( tcx) ;
1981
+ let src_sig = op. ty ( body, tcx) . fn_sig ( tcx) ;
1982
+
1983
+ // FIXME: Explained higher-ranked case.
1984
+ if src_sig. has_bound_regions ( )
1985
+ && let ty:: FnPtr ( target_sig) = * ty. kind ( )
1986
+ && let Some ( target_sig) = target_sig. no_bound_vars ( )
1987
+ {
1988
+ let src_sig = self . infcx . instantiate_binder_with_fresh_vars (
1989
+ span,
1990
+ BoundRegionConversionTime :: HigherRankedType ,
1991
+ src_sig,
1992
+ ) ;
1993
+ let src_ty = Ty :: new_fn_ptr ( self . tcx ( ) , ty:: Binder :: dummy ( src_sig) ) ;
1994
+ self . prove_predicate (
1995
+ ty:: ClauseKind :: WellFormed ( src_ty. into ( ) ) ,
1996
+ location. to_locations ( ) ,
1997
+ ConstraintCategory :: Cast { unsize_to : None } ,
1998
+ ) ;
1999
+
2000
+ let src_ty = self . normalize ( src_ty, location) ;
2001
+ if let Err ( terr) = self . sub_types (
2002
+ src_ty,
2003
+ * ty,
2004
+ location. to_locations ( ) ,
2005
+ ConstraintCategory :: Cast { unsize_to : None } ,
2006
+ ) {
2007
+ span_mirbug ! (
2008
+ self ,
2009
+ rvalue,
2010
+ "equating {:?} with {:?} yields {:?}" ,
2011
+ target_sig,
2012
+ src_sig,
2013
+ terr
2014
+ ) ;
2015
+ } ;
2016
+ }
2017
+
2018
+ let src_ty = Ty :: new_fn_ptr ( tcx, src_sig) ;
2019
+ // FIXME: Explain why this is needed.
2020
+ self . prove_predicate (
2021
+ ty:: ClauseKind :: WellFormed ( src_ty. into ( ) ) ,
2022
+ location. to_locations ( ) ,
2023
+ ConstraintCategory :: Cast { unsize_to : None } ,
2024
+ ) ;
1982
2025
1983
2026
// The type that we see in the fcx is like
1984
2027
// `foo::<'a, 'b>`, where `foo` is the path to a
1985
2028
// function definition. When we extract the
1986
2029
// signature, it comes from the `fn_sig` query,
1987
2030
// and hence may contain unnormalized results.
1988
- let fn_sig = self . normalize ( fn_sig, location) ;
1989
-
1990
- let ty_fn_ptr_from = Ty :: new_fn_ptr ( tcx, fn_sig) ;
1991
-
2031
+ let src_ty = self . normalize ( src_ty, location) ;
1992
2032
if let Err ( terr) = self . sub_types (
1993
- ty_fn_ptr_from ,
2033
+ src_ty ,
1994
2034
* ty,
1995
2035
location. to_locations ( ) ,
1996
2036
ConstraintCategory :: Cast { unsize_to : None } ,
@@ -1999,7 +2039,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
1999
2039
self ,
2000
2040
rvalue,
2001
2041
"equating {:?} with {:?} yields {:?}" ,
2002
- ty_fn_ptr_from ,
2042
+ src_ty ,
2003
2043
ty,
2004
2044
terr
2005
2045
) ;
0 commit comments