Use subtyping for UnsafeFnPointer coercion, too
This commit is contained in:
parent
636d7ff91b
commit
a97b41f188
@ -2043,9 +2043,9 @@ fn check_rvalue(&mut self, body: &Body<'tcx>, rvalue: &Rvalue<'tcx>, location: L
|
|||||||
|
|
||||||
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
|
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
|
||||||
|
|
||||||
if let Err(terr) = self.eq_types(
|
if let Err(terr) = self.sub_types(
|
||||||
*ty,
|
|
||||||
ty_fn_ptr_from,
|
ty_fn_ptr_from,
|
||||||
|
*ty,
|
||||||
location.to_locations(),
|
location.to_locations(),
|
||||||
ConstraintCategory::Cast { unsize_to: None },
|
ConstraintCategory::Cast { unsize_to: None },
|
||||||
) {
|
) {
|
||||||
|
14
tests/ui/coercion/cast-higher-ranked-unsafe-fn-ptr.rs
Normal file
14
tests/ui/coercion/cast-higher-ranked-unsafe-fn-ptr.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user