}
'f' => {
assert_eq!(self.next(), '[');
- let scope = self.parse_destruction_scope_data();
+ let scope = self.parse_scope();
assert_eq!(self.next(), '|');
let br = self.parse_bound_region();
assert_eq!(self.next(), ']');
})
}
- fn parse_destruction_scope_data(&mut self) -> region::DestructionScopeData {
- let node_id = self.parse_uint() as ast::NodeId;
- region::DestructionScopeData::new(node_id)
- }
-
fn parse_opt<T, F>(&mut self, f: F) -> Option<T>
where F: FnOnce(&mut TyDecoder<'a, 'tcx>) -> T,
{
}
ty::ReFree(ref fr) => {
mywrite!(w, "f[");
- enc_destruction_scope_data(w, fr.scope);
+ enc_scope(w, cx, fr.scope);
mywrite!(w, "|");
enc_bound_region(w, cx, fr.bound_region);
mywrite!(w, "]");
}
}
-fn enc_destruction_scope_data(w: &mut Encoder,
- d: region::DestructionScopeData) {
- mywrite!(w, "{}", d.node_id);
-}
-
fn enc_bound_region(w: &mut Encoder, cx: &ctxt, br: ty::BoundRegion) {
match br {
ty::BrAnon(idx) => {
tcx.region_maps.is_subscope_of(sub_scope, super_scope),
(ty::ReScope(sub_scope), ty::ReFree(fr)) =>
- tcx.region_maps.is_subscope_of(sub_scope,
- fr.scope.to_code_extent(&tcx.region_maps)) ||
+ tcx.region_maps.is_subscope_of(sub_scope, fr.scope) ||
self.is_static(fr),
(ty::ReFree(sub_fr), ty::ReFree(super_fr)) =>
}
};
- match self.map.find(fr.scope.node_id) {
+ match self.map.find(fr.scope.node_id(&self.region_maps)) {
Some(ast_map::NodeBlock(ref blk)) => {
let (msg, opt_span) = explain_span(self, "block", blk.span);
(format!("{} {}", prefix, msg), opt_span)
(format!("{} {}", prefix, msg), opt_span)
}
Some(_) | None => {
- // this really should not happen
+ // this really should not happen, but it does:
+ // FIXME(#27942)
(format!("{} unknown free region bounded by scope {:?}",
prefix, fr.scope), None)
}
return None
}
assert!(fr1.scope == fr2.scope);
- (fr1.scope.node_id, fr1, fr2)
+ (fr1.scope.node_id(&tcx.region_maps), fr1, fr2)
},
_ => return None
};
// A "free" region can be interpreted as "some region
// at least as big as the block fr.scope_id". So, we can
// reasonably compare free regions and scopes:
- let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
- let r_id = self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id);
+ let r_id = self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id);
- if r_id == fr_scope {
+ if r_id == fr.scope {
// if the free region's scope `fr.scope_id` is bigger than
// the scope region `s_id`, then the LUB is the free
// region itself:
// than the scope `s_id`, then we can say that the GLB
// is the scope `s_id`. Otherwise, as we do not know
// big the free region is precisely, the GLB is undefined.
- let fr_scope = fr.scope.to_code_extent(&self.tcx.region_maps);
- if self.tcx.region_maps.nearest_common_ancestor(fr_scope, s_id) == fr_scope ||
+ if self.tcx.region_maps.nearest_common_ancestor(fr.scope, s_id) == fr.scope ||
free_regions.is_static(fr) {
Ok(s)
} else {
Ok(ty::ReFree(*b))
} else {
this.intersect_scopes(ty::ReFree(*a), ty::ReFree(*b),
- a.scope.to_code_extent(&this.tcx.region_maps),
- b.scope.to_code_extent(&this.tcx.region_maps))
+ a.scope, b.scope)
}
}
}
use middle::def::*;
use middle::pat_util;
-use middle::region;
use middle::ty;
use lint;
use util::nodemap::NodeMap;
// within the fn body, late-bound regions are liberated:
let fn_ret =
self.ir.tcx.liberate_late_bound_regions(
- region::DestructionScopeData::new(body.id),
+ self.ir.tcx.region_maps.item_extent(body.id),
&self.fn_ret(id));
match fn_ret {
use middle::infer;
use middle::check_const;
use middle::def;
-use middle::region;
use middle::ty::{self, Ty};
use syntax::ast::{MutImmutable, MutMutable};
// The environment of a closure is guaranteed to
// outlive any bindings introduced in the body of the
// closure itself.
- scope: region::DestructionScopeData::new(fn_body_id),
+ scope: self.tcx().region_maps.item_extent(fn_body_id),
bound_region: ty::BrEnv
});
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
self.code_extent_interner.borrow()[&e]
}
+ pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
+ self.lookup_code_extent(CodeExtentData::Misc(n))
+ }
+ // Returns the code extent for an item - the destruction scope.
+ pub fn item_extent(&self, n: ast::NodeId) -> CodeExtent {
+ self.lookup_code_extent(CodeExtentData::DestructionScope(n))
+ }
pub fn intern_code_extent(&self,
e: CodeExtentData,
parent: CodeExtent) -> CodeExtent {
parent: CodeExtent) -> CodeExtent {
self.intern_code_extent(CodeExtentData::Misc(n), parent)
}
- pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
- self.lookup_code_extent(CodeExtentData::Misc(n))
- }
pub fn code_extent_data(&self, e: CodeExtent) -> CodeExtentData {
self.code_extents.borrow()[e.0 as usize]
}
/// A "free" region `fr` can be interpreted as "some region
/// at least as big as the scope `fr.scope`".
pub struct FreeRegion {
- pub scope: region::DestructionScopeData,
+ pub scope: region::CodeExtent,
pub bound_region: BoundRegion
}
types.push(def.space, self.mk_param_from_def(def));
}
- let free_id_outlive = region::DestructionScopeData::new(free_id);
+ let free_id_outlive = self.region_maps.item_extent(free_id);
// map bound 'a => free 'a
let mut regions = VecPerParamSpace::empty();
//
let free_substs = self.construct_free_substs(generics, free_id);
- let free_id_outlive = region::DestructionScopeData::new(free_id);
+ let free_id_outlive = self.region_maps.item_extent(free_id);
//
// Compute the bounds on Self and the type parameters.
let unnormalized_env = ty::ParameterEnvironment {
tcx: self,
free_substs: free_substs,
- implicit_region_bound: ty::ReScope(
- free_id_outlive.to_code_extent(&self.region_maps)),
+ implicit_region_bound: ty::ReScope(free_id_outlive),
caller_bounds: predicates,
selection_cache: traits::SelectionCache::new(),
free_id: free_id,
/// Replace any late-bound regions bound in `value` with free variants attached to scope-id
/// `scope_id`.
pub fn liberate_late_bound_regions<T>(&self,
- all_outlive_scope: region::DestructionScopeData,
+ all_outlive_scope: region::CodeExtent,
value: &Binder<T>)
-> T
where T : TypeFoldable<'tcx>
let loan_scope = match loan_region {
ty::ReScope(scope) => scope,
- ty::ReFree(ref fr) => {
- fr.scope.to_code_extent(&self.tcx().region_maps)
- }
+ ty::ReFree(ref fr) => fr.scope,
ty::ReStatic => {
// If we get here, an error must have been
Some(&rl::DefFreeRegion(scope, id)) => {
ty::ReFree(ty::FreeRegion {
- scope: scope,
+ scope: tcx.region_maps.item_extent(scope.node_id),
bound_region: ty::BrNamed(DefId::local(id),
lifetime.name)
})
use astconv;
use middle::def_id::DefId;
-use middle::region;
use middle::subst;
use middle::ty::{self, ToPolyTraitRef, Ty};
use std::cmp;
fcx.write_ty(expr.id, closure_type);
let fn_sig = fcx.tcx().liberate_late_bound_regions(
- region::DestructionScopeData::new(body.id), &fn_ty.sig);
+ fcx.tcx().region_maps.item_extent(body.id), &fn_ty.sig);
check_fn(fcx.ccx,
ast::Unsafety::Normal,
use middle::infer::type_variable;
use middle::pat_util::{self, pat_id_map};
use middle::privacy::{AllPublic, LastMod};
-use middle::region::{self};
use middle::subst::{self, Subst, Substs, VecPerParamSpace, ParamSpace, TypeSpace};
use middle::traits::{self, report_fulfillment_errors};
use middle::ty::{FnSig, GenericPredicates, TypeScheme};
let inh = Inherited::new(ccx.tcx, &tables, param_env);
// Compute the fty from point of view of inside fn.
+ let fn_scope = ccx.tcx.region_maps.item_extent(body.id);
let fn_sig =
fn_ty.sig.subst(ccx.tcx, &inh.infcx.parameter_environment.free_substs);
let fn_sig =
- ccx.tcx.liberate_late_bound_regions(region::DestructionScopeData::new(body.id),
- &fn_sig);
+ ccx.tcx.liberate_late_bound_regions(fn_scope, &fn_sig);
let fn_sig =
inh.normalize_associated_types_in(body.span,
body.id,
fcx: &'cx FnCtxt<'cx,'tcx>,
span: Span,
- // This field is often attached to item impls; it is not clear
- // that `CodeExtent` is well-defined for such nodes, so pnkfelix
- // has left it as a NodeId rather than porting to CodeExtent.
- scope: ast::NodeId,
+ scope: region::CodeExtent,
binding_count: usize,
cache: Option<&'cx mut HashSet<Ty<'tcx>>>,
scope: ast::NodeId,
cache: Option<&'cx mut HashSet<Ty<'tcx>>>)
-> BoundsChecker<'cx,'tcx> {
+ let scope = fcx.tcx().region_maps.item_extent(scope);
BoundsChecker { fcx: fcx, span: DUMMY_SP, scope: scope,
cache: cache, binding_count: 0 }
}
{
self.binding_count += 1;
let value = self.fcx.tcx().liberate_late_bound_regions(
- region::DestructionScopeData::new(self.scope),
+ self.scope,
binder);
debug!("BoundsChecker::fold_binder: late-bound regions replaced: {:?} at scope: {:?}",
value, self.scope);
use constrained_type_params::{identify_constrained_type_params, Parameter};
use CrateCtxt;
use middle::def_id::DefId;
-use middle::region::DestructionScopeData;
use middle::subst::{self, TypeSpace, FnSpace, ParamSpace, SelfSpace};
use middle::traits;
use middle::ty::{self, Ty};
{
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let fty = fcx.instantiate_type_scheme(span, free_substs, fty);
- let free_id_outlive = DestructionScopeData::new(free_id);
+ let free_id_outlive = fcx.tcx().region_maps.item_extent(free_id);
let sig = fcx.tcx().liberate_late_bound_regions(free_id_outlive, &fty.sig);
for &input_ty in &sig.inputs {
_ => typ,
};
- let body_scope = region::DestructionScopeData::new(body_id);
+ let body_scope = tcx.region_maps.item_extent(body_id);
// "Required type" comes from the trait definition. It may
// contain late-bound regions from the method, but not the
fn liberate_early_bound_regions<'tcx,T>(
tcx: &ty::ctxt<'tcx>,
- scope: region::DestructionScopeData,
+ scope: region::CodeExtent,
value: &T)
-> T
where T : TypeFoldable<'tcx>