From decbbb3fc03875e7b188d8ed30ded23a87d81696 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 1 Dec 2017 21:11:25 -0500 Subject: [PATCH] when reifying a safe fn as an unsafe fn ptr, insert two casts Otherwise, `run-pass/typeck-fn-to-unsafe-fn-ptr.rs` fails the MIR type checker. --- src/librustc_typeck/check/coercion.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 079dc2964a3..edda557c98c 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -638,9 +638,18 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { self.normalize_associated_types_in_as_infer_ok(self.cause.span, &a_sig); let a_fn_pointer = self.tcx.mk_fn_ptr(a_sig); - let InferOk { value, obligations: o2 } = - self.coerce_from_safe_fn(a_fn_pointer, a_sig, b, - simple(Adjust::ReifyFnPointer), simple(Adjust::ReifyFnPointer))?; + let InferOk { value, obligations: o2 } = self.coerce_from_safe_fn( + a_fn_pointer, + a_sig, + b, + |unsafe_ty| { + vec![ + Adjustment { kind: Adjust::ReifyFnPointer, target: a_fn_pointer }, + Adjustment { kind: Adjust::UnsafeFnPointer, target: unsafe_ty }, + ] + }, + simple(Adjust::ReifyFnPointer) + )?; obligations.extend(o2); Ok(InferOk { value, obligations })