No reason for it to live on `Inherited`.
//! and does not need to visit anything else.
use middle::const_val::ConstVal;
+use hir::def_id::DefId;
use ty::{self, Binder, Ty, TyCtxt, TypeFlags};
use std::fmt;
}
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,
value: &Binder<T>,
mut f: F)
(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`
/// becomes `for<'a,'b> Foo`.
pub fn flatten_late_bound_regions<T>(self, bound2_value: &Binder<Binder<T>>)
body: &hir::Body,
bound_sig: ty::PolyFnSig<'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(
body.value.span,
body.value.id,
let impl_fty = tcx.mk_fn_ptr(ty::Binder(impl_sig));
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,
&tcx.fn_sig(trait_m.def_id));
let trait_sig =
let ok = self.partially_normalize_associated_types_in(span, body_id, param_env, value);
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> }
// Compute the fty from point of view of inside fn.
let fn_sig =
- inh.liberate_late_bound_regions(def_id, &fn_sig);
+ tcx.liberate_late_bound_regions(def_id, &fn_sig);
let fn_sig =
inh.normalize_associated_types_in(body.value.span,
body_id.node_id,
implied_bounds: &mut Vec<Ty<'tcx>>)
{
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() {
fcx.register_wf_obligation(&input_ty, span, self.code.clone());
let sig = fcx.tcx.fn_sig(method.def_id);
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);
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,
&ty::Binder(self_ty)
);
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.liberate_late_bound_regions(
+ let self_arg_ty = fcx.tcx.liberate_late_bound_regions(
method.def_id,
&ty::Binder(self_arg_ty)
);