Use subtyping for UnsafeFnPointer coercion, too

This commit is contained in:
Michael Goulet 2024-08-19 21:26:10 -04:00
parent 636d7ff91b
commit a97b41f188
2 changed files with 16 additions and 2 deletions

View File

@ -2043,9 +2043,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
if let Err(terr) = self.eq_types(
*ty,
if let Err(terr) = self.sub_types(
ty_fn_ptr_from,
*ty,
location.to_locations(),
ConstraintCategory::Cast { unsize_to: None },
) {

View File

@ -0,0 +1,14 @@
//@ check-pass
fn higher_ranked_fndef(ctx: &mut ()) {}
fn test(higher_ranked_fnptr: fn(&mut ())) {
fn as_unsafe<T>(_: unsafe fn(T)) {}
// Make sure that we can cast higher-ranked fn items and pointers to
// a non-higher-ranked target.
as_unsafe(higher_ranked_fndef);
as_unsafe(higher_ranked_fnptr);
}
fn main() {}