Skip to content

Commit 7f247ad

Browse files
committed
move liberate_late_bound_regions to a method on the tcx
No reason for it to live on `Inherited`.
1 parent e9067bd commit 7f247ad

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

src/librustc/ty/fold.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! and does not need to visit anything else.
4141
4242
use middle::const_val::ConstVal;
43+
use hir::def_id::DefId;
4344
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
4445

4546
use std::fmt;
@@ -329,6 +330,14 @@ struct RegionReplacer<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
329330
}
330331

331332
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
333+
/// Replace all regions bound by the given `Binder` with the
334+
/// results returned by the closure; the closure is expected to
335+
/// return a free region (relative to this binder), and hence the
336+
/// binder is removed in the return type. The closure is invoked
337+
/// once for each unique `BoundRegion`; multiple references to the
338+
/// same `BoundRegion` will reuse the previous result. A map is
339+
/// returned at the end with each bound region and the free region
340+
/// that replaced it.
332341
pub fn replace_late_bound_regions<T,F>(self,
333342
value: &Binder<T>,
334343
mut f: F)
@@ -341,6 +350,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
341350
(result, replacer.map)
342351
}
343352

353+
/// Replace any late-bound regions bound in `value` with
354+
/// free variants attached to `all_outlive_scope`.
355+
pub fn liberate_late_bound_regions<T>(
356+
&self,
357+
all_outlive_scope: DefId,
358+
value: &ty::Binder<T>
359+
) -> T
360+
where T: TypeFoldable<'tcx> {
361+
self.replace_late_bound_regions(value, |br| {
362+
self.mk_region(ty::ReFree(ty::FreeRegion {
363+
scope: all_outlive_scope,
364+
bound_region: br
365+
}))
366+
}).0
367+
}
368+
344369
/// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
345370
/// becomes `for<'a,'b> Foo`.
346371
pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)

src/librustc_typeck/check/closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
562562
body: &hir::Body,
563563
bound_sig: ty::PolyFnSig<'tcx>,
564564
) -> ClosureSignatures<'tcx> {
565-
let liberated_sig = self.liberate_late_bound_regions(expr_def_id, &bound_sig);
565+
let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, &bound_sig);
566566
let liberated_sig = self.inh.normalize_associated_types_in(
567567
body.value.span,
568568
body.value.id,

src/librustc_typeck/check/compare_method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
270270
let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
271271
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
272272

273-
let trait_sig = inh.liberate_late_bound_regions(
273+
let trait_sig = tcx.liberate_late_bound_regions(
274274
impl_m.def_id,
275275
&tcx.fn_sig(trait_m.def_id));
276276
let trait_sig =

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -698,22 +698,6 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
698698
let ok = self.partially_normalize_associated_types_in(span, body_id, param_env, value);
699699
self.register_infer_ok_obligations(ok)
700700
}
701-
702-
/// Replace any late-bound regions bound in `value` with
703-
/// free variants attached to `all_outlive_scope`.
704-
fn liberate_late_bound_regions<T>(&self,
705-
all_outlive_scope: DefId,
706-
value: &ty::Binder<T>)
707-
-> T
708-
where T: TypeFoldable<'tcx>
709-
{
710-
self.tcx.replace_late_bound_regions(value, |br| {
711-
self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
712-
scope: all_outlive_scope,
713-
bound_region: br
714-
}))
715-
}).0
716-
}
717701
}
718702

719703
struct CheckItemTypesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
@@ -882,7 +866,7 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
882866

883867
// Compute the fty from point of view of inside fn.
884868
let fn_sig =
885-
inh.liberate_late_bound_regions(def_id, &fn_sig);
869+
tcx.liberate_late_bound_regions(def_id, &fn_sig);
886870
let fn_sig =
887871
inh.normalize_associated_types_in(body.value.span,
888872
body_id.node_id,

src/librustc_typeck/check/wfcheck.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
451451
implied_bounds: &mut Vec<Ty<'tcx>>)
452452
{
453453
let sig = fcx.normalize_associated_types_in(span, &sig);
454-
let sig = fcx.liberate_late_bound_regions(def_id, &sig);
454+
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
455455

456456
for input_ty in sig.inputs() {
457457
fcx.register_wf_obligation(&input_ty, span, self.code.clone());
@@ -484,12 +484,12 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
484484

485485
let sig = fcx.tcx.fn_sig(method.def_id);
486486
let sig = fcx.normalize_associated_types_in(span, &sig);
487-
let sig = fcx.liberate_late_bound_regions(method.def_id, &sig);
487+
let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &sig);
488488

489489
debug!("check_method_receiver: sig={:?}", sig);
490490

491491
let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
492-
let self_ty = fcx.liberate_late_bound_regions(
492+
let self_ty = fcx.tcx.liberate_late_bound_regions(
493493
method.def_id,
494494
&ty::Binder(self_ty)
495495
);
@@ -498,7 +498,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
498498

499499
let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
500500
let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
501-
let self_arg_ty = fcx.liberate_late_bound_regions(
501+
let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
502502
method.def_id,
503503
&ty::Binder(self_arg_ty)
504504
);

0 commit comments

Comments
 (0)