diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2017-11-30 12:22:11 -0300 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2017-12-13 06:03:27 -0500 |
| commit | ae035cb7311ab734630ba40d1b1409d76ac2105a (patch) | |
| tree | 3364567332fcb35e4d626805c914d9a25fee62a4 | |
| parent | 900d4d5bda06eb87b5a8a36713720095ef6951e1 (diff) | |
| download | rust-ae035cb7311ab734630ba40d1b1409d76ac2105a.tar.gz rust-ae035cb7311ab734630ba40d1b1409d76ac2105a.zip | |
Extract coerce_closure_fn_ty function
| -rw-r--r-- | src/librustc/ty/context.rs | 21 | ||||
| -rw-r--r-- | src/librustc_typeck/check/coercion.rs | 18 |
2 files changed, 22 insertions, 17 deletions
diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 4315d59f771..441dd792ee1 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1717,6 +1717,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { })) } + /// Create an unsafe fn ty based on a safe fn ty. + pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> { + let converted_sig = sig.map_bound(|s| { + let params_iter = match s.inputs()[0].sty { + ty::TyTuple(params, _) => { + params.into_iter().cloned() + } + _ => bug!(), + }; + self.mk_fn_sig( + params_iter, + s.output(), + s.variadic, + hir::Unsafety::Normal, + abi::Abi::Rust + ) + }); + + self.mk_fn_ptr(converted_sig) + } + // Interns a type/name combination, stores the resulting box in cx.interners, // and returns the box as cast to an unsafe ptr (see comments for Ty above). pub fn mk_ty(self, st: TypeVariants<'tcx>) -> Ty<'tcx> { diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index dc5d3141d4c..079dc2964a3 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -75,7 +75,6 @@ use rustc::ty::fold::TypeFoldable; use rustc::ty::error::TypeError; use rustc::ty::relate::RelateResult; use errors::DiagnosticBuilder; -use syntax::abi; use syntax::feature_gate; use syntax::ptr::P; use syntax_pos; @@ -670,22 +669,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> { // to // `fn(arg0,arg1,...) -> _` let sig = self.closure_sig(def_id_a, substs_a); - let converted_sig = sig.map_bound(|s| { - let params_iter = match s.inputs()[0].sty { - ty::TyTuple(params, _) => { - params.into_iter().cloned() - } - _ => bug!(), - }; - self.tcx.mk_fn_sig( - params_iter, - s.output(), - s.variadic, - hir::Unsafety::Normal, - abi::Abi::Rust - ) - }); - let pointer_ty = self.tcx.mk_fn_ptr(converted_sig); + let pointer_ty = self.tcx.coerce_closure_fn_ty(sig); debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty); self.unify_and(pointer_ty, b, simple(Adjust::ClosureFnPointer)) |
