Extract coerce_closure_fn_ty function
This commit is contained in:
parent
900d4d5bda
commit
ae035cb731
2 changed files with 22 additions and 17 deletions
|
@ -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,
|
// 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).
|
// 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> {
|
pub fn mk_ty(self, st: TypeVariants<'tcx>) -> Ty<'tcx> {
|
||||||
|
|
|
@ -75,7 +75,6 @@ use rustc::ty::fold::TypeFoldable;
|
||||||
use rustc::ty::error::TypeError;
|
use rustc::ty::error::TypeError;
|
||||||
use rustc::ty::relate::RelateResult;
|
use rustc::ty::relate::RelateResult;
|
||||||
use errors::DiagnosticBuilder;
|
use errors::DiagnosticBuilder;
|
||||||
use syntax::abi;
|
|
||||||
use syntax::feature_gate;
|
use syntax::feature_gate;
|
||||||
use syntax::ptr::P;
|
use syntax::ptr::P;
|
||||||
use syntax_pos;
|
use syntax_pos;
|
||||||
|
@ -670,22 +669,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
|
||||||
// to
|
// to
|
||||||
// `fn(arg0,arg1,...) -> _`
|
// `fn(arg0,arg1,...) -> _`
|
||||||
let sig = self.closure_sig(def_id_a, substs_a);
|
let sig = self.closure_sig(def_id_a, substs_a);
|
||||||
let converted_sig = sig.map_bound(|s| {
|
let pointer_ty = self.tcx.coerce_closure_fn_ty(sig);
|
||||||
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);
|
|
||||||
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})",
|
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})",
|
||||||
a, b, pointer_ty);
|
a, b, pointer_ty);
|
||||||
self.unify_and(pointer_ty, b, simple(Adjust::ClosureFnPointer))
|
self.unify_and(pointer_ty, b, simple(Adjust::ClosureFnPointer))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue