Skip to content

Commit d5ef3e2

Browse files
committed
replace InferCtxt::fn_sig with closure_sig
1 parent 05441ab commit d5ef3e2

File tree

7 files changed

+38
-46
lines changed

7 files changed

+38
-46
lines changed

src/librustc/infer/mod.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,38 +1480,18 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14801480
closure_kind_ty.to_opt_closure_kind()
14811481
}
14821482

1483-
/// Obtain the signature of a function or closure.
1484-
/// For closures, unlike `tcx.fn_sig(def_id)`, this method will
1485-
/// work during the type-checking of the enclosing function and
1486-
/// return the closure signature in its partially inferred state.
1487-
pub fn fn_sig(&self, def_id: DefId) -> ty::PolyFnSig<'tcx> {
1488-
// Do we have an in-progress set of tables we are inferring?
1489-
if let Some(tables) = self.in_progress_tables {
1490-
// Is this a local item?
1491-
if let Some(id) = self.tcx.hir.as_local_node_id(def_id) {
1492-
// Is it a local *closure*?
1493-
if self.tcx.is_closure(def_id) {
1494-
let hir_id = self.tcx.hir.node_to_hir_id(id);
1495-
// Is this local closure contained within the tables we are inferring?
1496-
if tables.borrow().local_id_root == Some(DefId::local(hir_id.owner)) {
1497-
// if so, extract signature from there.
1498-
let closure_ty = tables.borrow().node_id_to_type(hir_id);
1499-
let (closure_def_id, closure_substs) = match closure_ty.sty {
1500-
ty::TyClosure(closure_def_id, closure_substs) =>
1501-
(closure_def_id, closure_substs),
1502-
_ =>
1503-
bug!("closure with non-closure type: {:?}", closure_ty),
1504-
};
1505-
assert_eq!(def_id, closure_def_id);
1506-
let closure_sig_ty = closure_substs.closure_sig_ty(def_id, self.tcx);
1507-
let closure_sig_ty = self.shallow_resolve(&closure_sig_ty);
1508-
return closure_sig_ty.fn_sig(self.tcx);
1509-
}
1510-
}
1511-
}
1512-
}
1513-
1514-
self.tcx.fn_sig(def_id)
1483+
/// Obtain the signature of a closure. For closures, unlike
1484+
/// `tcx.fn_sig(def_id)`, this method will work during the
1485+
/// type-checking of the enclosing function and return the closure
1486+
/// signature in its partially inferred state.
1487+
pub fn closure_sig(
1488+
&self,
1489+
def_id: DefId,
1490+
substs: ty::ClosureSubsts<'tcx>
1491+
) -> ty::PolyFnSig<'tcx> {
1492+
let closure_sig_ty = substs.closure_sig_ty(def_id, self.tcx);
1493+
let closure_sig_ty = self.shallow_resolve(&closure_sig_ty);
1494+
closure_sig_ty.fn_sig(self.tcx)
15151495
}
15161496

15171497
/// Normalizes associated types in `value`, potentially returning

src/librustc/traits/project.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,26 +1339,27 @@ fn confirm_closure_candidate<'cx, 'gcx, 'tcx>(
13391339
vtable: VtableClosureData<'tcx, PredicateObligation<'tcx>>)
13401340
-> Progress<'tcx>
13411341
{
1342-
let closure_typer = selcx.closure_typer();
1343-
let closure_type = closure_typer.fn_sig(vtable.closure_def_id)
1344-
.subst(selcx.tcx(), vtable.substs.substs);
1342+
let tcx = selcx.tcx();
1343+
let infcx = selcx.infcx();
1344+
let closure_sig_ty = vtable.substs.closure_sig_ty(vtable.closure_def_id, tcx);
1345+
let closure_sig = infcx.shallow_resolve(&closure_sig_ty).fn_sig(tcx);
13451346
let Normalized {
1346-
value: closure_type,
1347+
value: closure_sig,
13471348
obligations
13481349
} = normalize_with_depth(selcx,
13491350
obligation.param_env,
13501351
obligation.cause.clone(),
13511352
obligation.recursion_depth+1,
1352-
&closure_type);
1353+
&closure_sig);
13531354

1354-
debug!("confirm_closure_candidate: obligation={:?},closure_type={:?},obligations={:?}",
1355+
debug!("confirm_closure_candidate: obligation={:?},closure_sig={:?},obligations={:?}",
13551356
obligation,
1356-
closure_type,
1357+
closure_sig,
13571358
obligations);
13581359

13591360
confirm_callable_candidate(selcx,
13601361
obligation,
1361-
closure_type,
1362+
closure_sig,
13621363
util::TupleArgumentsFlag::No)
13631364
.with_addl_obligations(vtable.nested)
13641365
.with_addl_obligations(obligations)

src/librustc/traits/select.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,8 +3183,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31833183
substs: ty::ClosureSubsts<'tcx>)
31843184
-> ty::PolyTraitRef<'tcx>
31853185
{
3186-
let closure_type = self.infcx.fn_sig(closure_def_id)
3187-
.subst(self.tcx(), substs.substs);
3186+
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
31883187
let ty::Binder((trait_ref, _)) =
31893188
self.tcx().closure_trait_ref_and_return_type(obligation.predicate.def_id(),
31903189
obligation.predicate.0.self_ty(), // (1)

src/librustc/ty/sty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,13 +356,17 @@ impl<'tcx> ClosureSubsts<'tcx> {
356356
/// Returns the closure kind for this closure; only usable outside
357357
/// of an inference context, because in that context we know that
358358
/// there are no type variables.
359+
///
360+
/// If you have an inference context, use `infcx.closure_kind()`.
359361
pub fn closure_kind(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::ClosureKind {
360362
self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap()
361363
}
362364

363365
/// Extracts the signature from the closure; only usable outside
364366
/// of an inference context, because in that context we know that
365367
/// there are no type variables.
368+
///
369+
/// If you have an inference context, use `infcx.closure_sig()`.
366370
pub fn closure_sig(self, def_id: DefId, tcx: TyCtxt<'_, 'tcx, 'tcx>) -> ty::PolyFnSig<'tcx> {
367371
match self.closure_sig_ty(def_id, tcx).sty {
368372
ty::TyFnPtr(sig) => sig,

src/librustc_mir/borrow_check/nll/universal_regions.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ const FR: NLLRegionVariableOrigin = NLLRegionVariableOrigin::FreeRegion;
381381

382382
impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
383383
fn build(mut self) -> UniversalRegions<'tcx> {
384+
debug!("build(mir_def_id={:?})", self.mir_def_id);
385+
384386
let param_env = self.param_env;
387+
debug!("build: param_env={:?}", param_env);
385388

386389
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());
387390

@@ -393,8 +396,10 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
393396
let first_extern_index = self.infcx.num_region_vars();
394397

395398
let defining_ty = self.defining_ty();
399+
debug!("build: defining_ty={:?}", defining_ty);
396400

397401
let indices = self.compute_indices(fr_static, defining_ty);
402+
debug!("build: indices={:?}", indices);
398403

399404
let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty);
400405

@@ -410,12 +415,14 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
410415

411416
// Add the implied bounds from inputs and outputs.
412417
for ty in inputs_and_output {
418+
debug!("build: input_or_output={:?}", ty);
413419
self.add_implied_bounds(&indices, ty);
414420
}
415421

416422
// Finally, outlives is reflexive, and static outlives every
417423
// other free region.
418424
for fr in (FIRST_GLOBAL_INDEX..num_universals).map(RegionVid::new) {
425+
debug!("build: relating free region {:?} to itself and to 'static", fr);
419426
self.relations.relate_universal_regions(fr, fr);
420427
self.relations.relate_universal_regions(fr_static, fr);
421428
}
@@ -562,6 +569,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
562569
///
563570
/// Assumes that `universal_regions` indices map is fully constructed.
564571
fn add_implied_bounds(&mut self, indices: &UniversalRegionIndices<'tcx>, ty: Ty<'tcx>) {
572+
debug!("add_implied_bounds(ty={:?})", ty);
565573
let span = self.infcx.tcx.def_span(self.mir_def_id);
566574
let bounds = self.infcx
567575
.implied_outlives_bounds(self.param_env, self.mir_node_id, ty, span);
@@ -576,6 +584,8 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> {
576584
I: IntoIterator<Item = OutlivesBound<'tcx>>,
577585
{
578586
for outlives_bound in outlives_bounds {
587+
debug!("add_outlives_bounds(bound={:?})", outlives_bound);
588+
579589
match outlives_bound {
580590
OutlivesBound::RegionSubRegion(r1, r2) => {
581591
// The bound says that `r1 <= r2`; we store `r2: r1`.

src/librustc_typeck/check/callee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use hir::def::Def;
1616
use hir::def_id::{DefId, LOCAL_CRATE};
1717
use rustc::{infer, traits};
1818
use rustc::ty::{self, TyCtxt, TypeFoldable, LvaluePreference, Ty};
19-
use rustc::ty::subst::Subst;
2019
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
2120
use syntax::abi;
2221
use syntax::symbol::Symbol;
@@ -109,7 +108,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
109108
// haven't yet decided on whether the closure is fn vs
110109
// fnmut vs fnonce. If so, we have to defer further processing.
111110
if self.closure_kind(def_id, substs).is_none() {
112-
let closure_ty = self.fn_sig(def_id).subst(self.tcx, substs.substs);
111+
let closure_ty = self.closure_sig(def_id, substs);
113112
let fn_sig = self.replace_late_bound_regions_with_fresh_var(call_expr.span,
114113
infer::FnCall,
115114
&closure_ty)

src/librustc_typeck/check/coercion.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ use rustc::ty::{self, LvaluePreference, TypeAndMut,
7474
use rustc::ty::fold::TypeFoldable;
7575
use rustc::ty::error::TypeError;
7676
use rustc::ty::relate::RelateResult;
77-
use rustc::ty::subst::Subst;
7877
use errors::DiagnosticBuilder;
7978
use syntax::abi;
8079
use syntax::feature_gate;
@@ -670,7 +669,7 @@ impl<'f, 'gcx, 'tcx> Coerce<'f, 'gcx, 'tcx> {
670669
// `extern "rust-call" fn((arg0,arg1,...)) -> _`
671670
// to
672671
// `fn(arg0,arg1,...) -> _`
673-
let sig = self.fn_sig(def_id_a).subst(self.tcx, substs_a.substs);
672+
let sig = self.closure_sig(def_id_a, substs_a);
674673
let converted_sig = sig.map_bound(|s| {
675674
let params_iter = match s.inputs()[0].sty {
676675
ty::TyTuple(params, _) => {

0 commit comments

Comments
 (0)