move liberate_late_bound_regions
to a method on the tcx
No reason for it to live on `Inherited`.
This commit is contained in:
parent
e9067bd5cc
commit
7f247add41
5 changed files with 32 additions and 23 deletions
|
@ -40,6 +40,7 @@
|
||||||
//! and does not need to visit anything else.
|
//! and does not need to visit anything else.
|
||||||
|
|
||||||
use middle::const_val::ConstVal;
|
use middle::const_val::ConstVal;
|
||||||
|
use hir::def_id::DefId;
|
||||||
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
|
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
@ -329,6 +330,14 @@ struct RegionReplacer<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
|
/// Replace all regions bound by the given `Binder` with the
|
||||||
|
/// results returned by the closure; the closure is expected to
|
||||||
|
/// return a free region (relative to this binder), and hence the
|
||||||
|
/// binder is removed in the return type. The closure is invoked
|
||||||
|
/// once for each unique `BoundRegion`; multiple references to the
|
||||||
|
/// same `BoundRegion` will reuse the previous result. A map is
|
||||||
|
/// returned at the end with each bound region and the free region
|
||||||
|
/// that replaced it.
|
||||||
pub fn replace_late_bound_regions<T,F>(self,
|
pub fn replace_late_bound_regions<T,F>(self,
|
||||||
value: &Binder<T>,
|
value: &Binder<T>,
|
||||||
mut f: F)
|
mut f: F)
|
||||||
|
@ -341,6 +350,22 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
||||||
(result, replacer.map)
|
(result, replacer.map)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Replace any late-bound regions bound in `value` with
|
||||||
|
/// free variants attached to `all_outlive_scope`.
|
||||||
|
pub fn liberate_late_bound_regions<T>(
|
||||||
|
&self,
|
||||||
|
all_outlive_scope: DefId,
|
||||||
|
value: &ty::Binder<T>
|
||||||
|
) -> T
|
||||||
|
where T: TypeFoldable<'tcx> {
|
||||||
|
self.replace_late_bound_regions(value, |br| {
|
||||||
|
self.mk_region(ty::ReFree(ty::FreeRegion {
|
||||||
|
scope: all_outlive_scope,
|
||||||
|
bound_region: br
|
||||||
|
}))
|
||||||
|
}).0
|
||||||
|
}
|
||||||
|
|
||||||
/// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
|
/// Flattens two binding levels into one. So `for<'a> for<'b> Foo`
|
||||||
/// becomes `for<'a,'b> Foo`.
|
/// becomes `for<'a,'b> Foo`.
|
||||||
pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)
|
pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)
|
||||||
|
|
|
@ -562,7 +562,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
body: &hir::Body,
|
body: &hir::Body,
|
||||||
bound_sig: ty::PolyFnSig<'tcx>,
|
bound_sig: ty::PolyFnSig<'tcx>,
|
||||||
) -> ClosureSignatures<'tcx> {
|
) -> ClosureSignatures<'tcx> {
|
||||||
let liberated_sig = self.liberate_late_bound_regions(expr_def_id, &bound_sig);
|
let liberated_sig = self.tcx().liberate_late_bound_regions(expr_def_id, &bound_sig);
|
||||||
let liberated_sig = self.inh.normalize_associated_types_in(
|
let liberated_sig = self.inh.normalize_associated_types_in(
|
||||||
body.value.span,
|
body.value.span,
|
||||||
body.value.id,
|
body.value.id,
|
||||||
|
|
|
@ -270,7 +270,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
|
let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
|
||||||
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
|
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
|
||||||
|
|
||||||
let trait_sig = inh.liberate_late_bound_regions(
|
let trait_sig = tcx.liberate_late_bound_regions(
|
||||||
impl_m.def_id,
|
impl_m.def_id,
|
||||||
&tcx.fn_sig(trait_m.def_id));
|
&tcx.fn_sig(trait_m.def_id));
|
||||||
let trait_sig =
|
let trait_sig =
|
||||||
|
|
|
@ -698,22 +698,6 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
|
||||||
let ok = self.partially_normalize_associated_types_in(span, body_id, param_env, value);
|
let ok = self.partially_normalize_associated_types_in(span, body_id, param_env, value);
|
||||||
self.register_infer_ok_obligations(ok)
|
self.register_infer_ok_obligations(ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replace any late-bound regions bound in `value` with
|
|
||||||
/// free variants attached to `all_outlive_scope`.
|
|
||||||
fn liberate_late_bound_regions<T>(&self,
|
|
||||||
all_outlive_scope: DefId,
|
|
||||||
value: &ty::Binder<T>)
|
|
||||||
-> T
|
|
||||||
where T: TypeFoldable<'tcx>
|
|
||||||
{
|
|
||||||
self.tcx.replace_late_bound_regions(value, |br| {
|
|
||||||
self.tcx.mk_region(ty::ReFree(ty::FreeRegion {
|
|
||||||
scope: all_outlive_scope,
|
|
||||||
bound_region: br
|
|
||||||
}))
|
|
||||||
}).0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CheckItemTypesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx> }
|
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>,
|
||||||
|
|
||||||
// Compute the fty from point of view of inside fn.
|
// Compute the fty from point of view of inside fn.
|
||||||
let fn_sig =
|
let fn_sig =
|
||||||
inh.liberate_late_bound_regions(def_id, &fn_sig);
|
tcx.liberate_late_bound_regions(def_id, &fn_sig);
|
||||||
let fn_sig =
|
let fn_sig =
|
||||||
inh.normalize_associated_types_in(body.value.span,
|
inh.normalize_associated_types_in(body.value.span,
|
||||||
body_id.node_id,
|
body_id.node_id,
|
||||||
|
|
|
@ -451,7 +451,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
|
||||||
implied_bounds: &mut Vec<Ty<'tcx>>)
|
implied_bounds: &mut Vec<Ty<'tcx>>)
|
||||||
{
|
{
|
||||||
let sig = fcx.normalize_associated_types_in(span, &sig);
|
let sig = fcx.normalize_associated_types_in(span, &sig);
|
||||||
let sig = fcx.liberate_late_bound_regions(def_id, &sig);
|
let sig = fcx.tcx.liberate_late_bound_regions(def_id, &sig);
|
||||||
|
|
||||||
for input_ty in sig.inputs() {
|
for input_ty in sig.inputs() {
|
||||||
fcx.register_wf_obligation(&input_ty, span, self.code.clone());
|
fcx.register_wf_obligation(&input_ty, span, self.code.clone());
|
||||||
|
@ -484,12 +484,12 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
|
||||||
|
|
||||||
let sig = fcx.tcx.fn_sig(method.def_id);
|
let sig = fcx.tcx.fn_sig(method.def_id);
|
||||||
let sig = fcx.normalize_associated_types_in(span, &sig);
|
let sig = fcx.normalize_associated_types_in(span, &sig);
|
||||||
let sig = fcx.liberate_late_bound_regions(method.def_id, &sig);
|
let sig = fcx.tcx.liberate_late_bound_regions(method.def_id, &sig);
|
||||||
|
|
||||||
debug!("check_method_receiver: sig={:?}", sig);
|
debug!("check_method_receiver: sig={:?}", sig);
|
||||||
|
|
||||||
let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
|
let self_ty = fcx.normalize_associated_types_in(span, &self_ty);
|
||||||
let self_ty = fcx.liberate_late_bound_regions(
|
let self_ty = fcx.tcx.liberate_late_bound_regions(
|
||||||
method.def_id,
|
method.def_id,
|
||||||
&ty::Binder(self_ty)
|
&ty::Binder(self_ty)
|
||||||
);
|
);
|
||||||
|
@ -498,7 +498,7 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
|
||||||
|
|
||||||
let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
|
let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
|
||||||
let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
|
let self_arg_ty = fcx.normalize_associated_types_in(span, &self_arg_ty);
|
||||||
let self_arg_ty = fcx.liberate_late_bound_regions(
|
let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
|
||||||
method.def_id,
|
method.def_id,
|
||||||
&ty::Binder(self_arg_ty)
|
&ty::Binder(self_arg_ty)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue