Skip to content

Commit ae035cb

Browse files
spastorinonikomatsakis
authored andcommitted
Extract coerce_closure_fn_ty function
1 parent 900d4d5 commit ae035cb

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/librustc/ty/context.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,27 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
17171717
}))
17181718
}
17191719

1720+
/// Create an unsafe fn ty based on a safe fn ty.
1721+
pub fn coerce_closure_fn_ty(self, sig: PolyFnSig<'tcx>) -> Ty<'tcx> {
1722+
let converted_sig = sig.map_bound(|s| {
1723+
let params_iter = match s.inputs()[0].sty {
1724+
ty::TyTuple(params, _) => {
1725+
params.into_iter().cloned()
1726+
}
1727+
_ => bug!(),
1728+
};
1729+
self.mk_fn_sig(
1730+
params_iter,
1731+
s.output(),
1732+
s.variadic,
1733+
hir::Unsafety::Normal,
1734+
abi::Abi::Rust
1735+
)
1736+
});
1737+
1738+
self.mk_fn_ptr(converted_sig)
1739+
}
1740+
17201741
// Interns a type/name combination, stores the resulting box in cx.interners,
17211742
// and returns the box as cast to an unsafe ptr (see comments for Ty above).
17221743
pub fn mk_ty(self, st: TypeVariants<'tcx>) -> Ty<'tcx> {

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ use rustc::ty::fold::TypeFoldable;
7575
use rustc::ty::error::TypeError;
7676
use rustc::ty::relate::RelateResult;
7777
use errors::DiagnosticBuilder;
78-
use syntax::abi;
7978
use syntax::feature_gate;
8079
use syntax::ptr::P;
8180
use syntax_pos;
@@ -670,22 +669,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
670669
// to
671670
// `fn(arg0,arg1,...) -> _`
672671
let sig = self.closure_sig(def_id_a, substs_a);
673-
let converted_sig = sig.map_bound(|s| {
674-
let params_iter = match s.inputs()[0].sty {
675-
ty::TyTuple(params, _) => {
676-
params.into_iter().cloned()
677-
}
678-
_ => bug!(),
679-
};
680-
self.tcx.mk_fn_sig(
681-
params_iter,
682-
s.output(),
683-
s.variadic,
684-
hir::Unsafety::Normal,
685-
abi::Abi::Rust
686-
)
687-
});
688-
let pointer_ty = self.tcx.mk_fn_ptr(converted_sig);
672+
let pointer_ty = self.tcx.coerce_closure_fn_ty(sig);
689673
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})",
690674
a, b, pointer_ty);
691675
self.unify_and(pointer_ty, b, simple(Adjust::ClosureFnPointer))

0 commit comments

Comments
 (0)