Skip to content

Commit 41c1678

Browse files
authored
Unrolled build for rust-lang#129288
Rollup merge of rust-lang#129288 - compiler-errors:unsafe-fn-coercion, r=lcnr Use subtyping for `UnsafeFnPointer` coercion, too I overlooked this in rust-lang#129059, which changed MIR typechecking to use subtyping for other fn pointer coercions. Fixes rust-lang#129285
2 parents 3f121b9 + a97b41f commit 41c1678

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2043,9 +2043,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20432043

20442044
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
20452045

2046-
if let Err(terr) = self.eq_types(
2047-
*ty,
2046+
if let Err(terr) = self.sub_types(
20482047
ty_fn_ptr_from,
2048+
*ty,
20492049
location.to_locations(),
20502050
ConstraintCategory::Cast { unsize_to: None },
20512051
) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ check-pass
2+
3+
fn higher_ranked_fndef(ctx: &mut ()) {}
4+
5+
fn test(higher_ranked_fnptr: fn(&mut ())) {
6+
fn as_unsafe<T>(_: unsafe fn(T)) {}
7+
8+
// Make sure that we can cast higher-ranked fn items and pointers to
9+
// a non-higher-ranked target.
10+
as_unsafe(higher_ranked_fndef);
11+
as_unsafe(higher_ranked_fnptr);
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)