ty::ReEmpty |
ty::ReErased => {
// replace all free regions with 'erased
- self.tcx().mk_region(ty::ReErased)
+ self.tcx().types.re_erased
}
}
}
} else {
// otherwise, we don't know what the free region is,
// so we must conservatively say the LUB is static:
- self.tcx.mk_region(ReStatic)
+ self.tcx.types.re_static
}
}
if a == b {
a
} else {
- self.tcx.mk_region(ReStatic)
+ self.tcx.types.re_static
}
}
}
fn construct_var_data(&self) -> Vec<VarValue<'tcx>> {
(0..self.num_vars() as usize)
- .map(|_| Value(self.tcx.mk_region(ty::ReEmpty)))
+ .map(|_| Value(self.tcx.types.re_empty))
.collect()
}
-> &'tcx ty::Region {
match values[rid.index as usize] {
Value(r) => r,
- ErrorValue => tcx.mk_region(ReStatic), // Previously reported error.
+ ErrorValue => tcx.types.re_static, // Previously reported error.
}
}
hir::ExprMatch(ref discr, ref arms, _) => {
let discr_cmt = return_if_err!(self.mc.cat_expr(&discr));
- let r = self.tcx().mk_region(ty::ReEmpty);
+ let r = self.tcx().types.re_empty;
self.borrow_expr(&discr, r, ty::ImmBorrow, MatchDiscriminant);
// treatment of the discriminant is handled while walking the arms.
// we can promote to a constant, otherwise equal to enclosing temp
// lifetime.
let (re, old_re) = if promotable {
- (self.tcx().mk_region(ty::ReStatic),
- self.tcx().mk_region(ty::ReStatic))
+ (self.tcx().types.re_static,
+ self.tcx().types.re_static)
} else {
self.temporary_scope(id)
};
// Otherwise, we have something of the form
// `for<'a> T: 'a where 'a not in T`, which we can treat as `T: 'static`.
Some(t_a) => {
- let r_static = selcx.tcx().mk_region(ty::ReStatic);
+ let r_static = selcx.tcx().types.re_static;
register_region_obligation(t_a, r_static,
obligation.cause.clone(),
region_obligations);
// the method may have some early-bound lifetimes, add
// regions for those
let substs = Substs::for_item(tcx, def_id,
- |_, _| tcx.mk_region(ty::ReErased),
+ |_, _| tcx.types.re_erased,
|def, _| trait_ref.substs().type_for_def(def));
// the trait type may have higher-ranked lifetimes in it;
pub f64: Ty<'tcx>,
pub never: Ty<'tcx>,
pub err: Ty<'tcx>,
+
+ pub re_empty: &'tcx Region,
+ pub re_static: &'tcx Region,
+ pub re_erased: &'tcx Region,
}
#[derive(RustcEncodable, RustcDecodable)]
impl<'tcx> CommonTypes<'tcx> {
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
let mk = |sty| interners.intern_ty(sty, None);
+ let mk_region = |r| {
+ if let Some(r) = interners.region.borrow().get(&r) {
+ return r.0;
+ }
+ let r = interners.arena.alloc(r);
+ interners.region.borrow_mut().insert(Interned(r));
+ &*r
+ };
CommonTypes {
bool: mk(TyBool),
char: mk(TyChar),
u128: mk(TyUint(ast::UintTy::U128)),
f32: mk(TyFloat(ast::FloatTy::F32)),
f64: mk(TyFloat(ast::FloatTy::F64)),
+
+ re_empty: mk_region(Region::ReEmpty),
+ re_static: mk_region(Region::ReStatic),
+ re_erased: mk_region(Region::ReErased),
}
}
}
}
pub fn mk_static_str(self) -> Ty<'tcx> {
- self.mk_imm_ref(self.mk_region(ty::ReStatic), self.mk_str())
+ self.mk_imm_ref(self.types.re_static, self.mk_str())
}
pub fn mk_adt(self, def: &'tcx AdtDef, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> {
pub fn erase_late_bound_regions<T>(self, value: &Binder<T>) -> T
where T : TypeFoldable<'tcx>
{
- self.replace_late_bound_regions(value, |_| self.mk_region(ty::ReErased)).0
+ self.replace_late_bound_regions(value, |_| self.types.re_erased).0
}
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
// whenever a substitution occurs.
match *r {
ty::ReLateBound(..) => r,
- _ => self.tcx().mk_region(ty::ReErased)
+ _ => self.tcx().types.re_erased
}
}
}
}
}
+pub fn shift_region_ref<'a, 'gcx, 'tcx>(
+ tcx: TyCtxt<'a, 'gcx, 'tcx>,
+ region: &'tcx ty::Region,
+ amount: u32)
+ -> &'tcx ty::Region
+{
+ match region {
+ &ty::ReLateBound(debruijn, br) if amount > 0 => {
+ tcx.mk_region(ty::ReLateBound(debruijn.shifted(amount), br))
+ }
+ _ => {
+ region
+ }
+ }
+}
+
pub fn shift_regions<'a, 'gcx, 'tcx, T>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
amount: u32, value: &T) -> T
where T: TypeFoldable<'tcx>
value, amount);
value.fold_with(&mut RegionFolder::new(tcx, &mut false, &mut |region, _current_depth| {
- tcx.mk_region(shift_region(*region, amount))
+ shift_region_ref(tcx, region, amount)
}))
}
/// Construct a parameter environment suitable for static contexts or other contexts where there
/// are no free type/lifetime parameters in scope.
pub fn empty_parameter_environment(self) -> ParameterEnvironment<'tcx> {
-
- // for an empty parameter environment, there ARE no free
- // regions, so it shouldn't matter what we use for the free id
- let free_id_outlive = self.region_maps.node_extent(ast::DUMMY_NODE_ID);
ty::ParameterEnvironment {
free_substs: self.intern_substs(&[]),
caller_bounds: Vec::new(),
- implicit_region_bound: self.mk_region(ty::ReEmpty),
- free_id_outlive: free_id_outlive,
+ implicit_region_bound: self.types.re_empty,
+ // for an empty parameter environment, there ARE no free
+ // regions, so it shouldn't matter what we use for the free id
+ free_id_outlive: ROOT_CODE_EXTENT,
is_copy_cache: RefCell::new(FxHashMap()),
is_sized_cache: RefCell::new(FxHashMap()),
is_freeze_cache: RefCell::new(FxHashMap()),
pub struct CrateInherentImpls {
pub inherent_impls: DefIdMap<Rc<Vec<DefId>>>,
}
-
}
fn shift_region_through_binders(&self, region: &'tcx ty::Region) -> &'tcx ty::Region {
+ if self.region_binders_passed == 0 || !region.has_escaping_regions() {
+ return region;
+ }
self.tcx().mk_region(ty::fold::shift_region(*region, self.region_binders_passed))
}
}
/// a suitable "empty substs" for it.
pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> &'tcx ty::Substs<'tcx> {
ty::Substs::for_item(self, item_def_id,
- |_, _| self.mk_region(ty::ReErased),
+ |_, _| self.types.re_erased,
|_, _| {
bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
})
}
Categorization::StaticItem |
Categorization::Deref(.., mc::UnsafePtr(..)) => {
- self.bccx.tcx.mk_region(ty::ReStatic)
+ self.bccx.tcx.types.re_static
}
Categorization::Deref(.., mc::BorrowedPtr(_, r)) |
Categorization::Deref(.., mc::Implicit(_, r)) => {
}
pub fn t_rptr_static(&self) -> Ty<'tcx> {
- self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(ty::ReStatic),
+ self.infcx.tcx.mk_imm_ref(self.infcx.tcx.types.re_static,
self.tcx().types.isize)
}
pub fn t_rptr_empty(&self) -> Ty<'tcx> {
- self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(ty::ReEmpty),
+ self.infcx.tcx.mk_imm_ref(self.infcx.tcx.types.re_empty,
self.tcx().types.isize)
}
assert!(ty.is_slice());
let array_ty = tcx.mk_array(tcx.types.u8, bytes.len());
- let array_ref = tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic), array_ty);
+ let array_ref = tcx.mk_imm_ref(tcx.types.re_static, array_ty);
let array = self.literal_operand(test.span, array_ref, Literal::Value {
value: value.clone()
});
Adjustment::Deref => Operand::Consume(rcvr_l.deref()),
Adjustment::RefMut => {
// let rcvr = &mut rcvr;
- let re_erased = tcx.mk_region(ty::ReErased);
let ref_rcvr = local_decls.push(temp_decl(
Mutability::Not,
- tcx.mk_ref(re_erased, ty::TypeAndMut {
+ tcx.mk_ref(tcx.types.re_erased, ty::TypeAndMut {
ty: sig.inputs()[0],
mutbl: hir::Mutability::MutMutable
}),
source_info: source_info,
kind: StatementKind::Assign(
Lvalue::Local(ref_rcvr),
- Rvalue::Ref(re_erased, BorrowKind::Mut, rcvr_l)
+ Rvalue::Ref(tcx.types.re_erased, BorrowKind::Mut, rcvr_l)
)
});
Operand::Consume(Lvalue::Local(ref_rcvr))
//! care erasing regions all over the place.
use rustc::ty::subst::Substs;
-use rustc::ty::{Ty, TyCtxt, ReErased, ClosureSubsts};
+use rustc::ty::{Ty, TyCtxt, ClosureSubsts};
use rustc::mir::*;
use rustc::mir::visit::MutVisitor;
use rustc::mir::transform::{MirPass, MirSource, Pass};
fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) {
match *rvalue {
Rvalue::Ref(ref mut r, _, _) => {
- *r = self.tcx.mk_region(ReErased);
+ *r = self.tcx.types.re_erased;
}
Rvalue::Use(..) |
Rvalue::Repeat(..) |
let dest = if dest_needs_borrow(&destination.0) {
debug!("Creating temp for return destination");
let dest = Rvalue::Ref(
- self.tcx.mk_region(ty::ReErased),
+ self.tcx.types.re_erased,
BorrowKind::Mut,
destination.0);
fn cast_box_free_arg(&self, arg: Lvalue<'tcx>, ptr_ty: Ty<'tcx>,
callsite: &CallSite<'tcx>, caller_mir: &mut Mir<'tcx>) -> Operand<'tcx> {
let arg = Rvalue::Ref(
- self.tcx.mk_region(ty::ReErased),
+ self.tcx.types.re_erased,
BorrowKind::Mut,
arg.deref());
let ty = self.lvalue_ty(self.lvalue);
let substs = tcx.mk_substs(iter::once(Kind::from(ty)));
- let re_erased = tcx.mk_region(ty::ReErased);
- let ref_ty = tcx.mk_ref(re_erased, ty::TypeAndMut {
+ let ref_ty = tcx.mk_ref(tcx.types.re_erased, ty::TypeAndMut {
ty: ty,
mutbl: hir::Mutability::MutMutable
});
source_info: self.source_info,
kind: StatementKind::Assign(
Lvalue::Local(ref_lvalue),
- Rvalue::Ref(re_erased, BorrowKind::Mut, self.lvalue.clone())
+ Rvalue::Ref(tcx.types.re_erased, BorrowKind::Mut, self.lvalue.clone())
)
}],
terminator: Some(Terminator {
let tr_lvalue = self.const_lvalue(lvalue, span)?;
let ty = tr_lvalue.ty;
- let ref_ty = tcx.mk_ref(tcx.mk_region(ty::ReErased),
+ let ref_ty = tcx.mk_ref(tcx.types.re_erased,
ty::TypeAndMut { ty: ty, mutbl: bk.to_mutbl_lossy() });
let base = match tr_lvalue.base {
let ty = tr_lvalue.ty.to_ty(bcx.tcx());
let ref_ty = bcx.tcx().mk_ref(
- bcx.tcx().mk_region(ty::ReErased),
+ bcx.tcx().types.re_erased,
ty::TypeAndMut { ty: ty, mutbl: bk.to_mutbl_lossy() }
);
let tcx = self.tcx();
let r = match tcx.named_region_map.defs.get(&lifetime.id) {
Some(&rl::Region::Static) => {
- tcx.mk_region(ty::ReStatic)
+ tcx.types.re_static
}
Some(&rl::Region::LateBound(debruijn, id)) => {
.emit();
return Substs::for_item(tcx, def_id, |_, _| {
- tcx.mk_region(ty::ReStatic)
+ tcx.types.re_static
}, |_, _| {
tcx.types.err
});
if let Some(lifetime) = lifetimes.get(i) {
self.ast_region_to_region(lifetime, Some(def))
} else {
- tcx.mk_region(ty::ReStatic)
+ tcx.types.re_static
}
}, |def, substs| {
let i = def.index as usize;
span_err!(tcx.sess, span, E0228,
"the lifetime bound for this object type cannot be deduced \
from context; please supply an explicit bound");
- tcx.mk_region(ty::ReStatic)
+ tcx.types.re_static
})
}
})
// If any of the derived region bounds are 'static, that is always
// the best choice.
if derived_region_bounds.iter().any(|&r| ty::ReStatic == *r) {
- return Some(tcx.mk_region(ty::ReStatic));
+ return Some(tcx.types.re_static);
}
// Determine whether there is exactly one unique region in the set
let expected_ty = self.structurally_resolved_type(pat.span, expected);
if let ty::TyRef(_, mt) = expected_ty.sty {
if let ty::TySlice(_) = mt.ty.sty {
- pat_ty = tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
+ pat_ty = tcx.mk_imm_ref(tcx.types.re_static,
tcx.mk_slice(tcx.types.u8))
}
}
let impl_self_orig = self_substs.region_for_def(def);
let r = if let ty::Region::ReEarlyBound(ref ebr) = *impl_self_orig {
if impl_bindings.region_param(ebr).pure_wrt_drop {
- tcx.mk_region(ty::ReStatic)
+ tcx.types.re_static
} else {
r_orig
}
let def_id = tcx.hir.local_def_id(it.id);
let substs = Substs::for_item(tcx, def_id,
- |_, _| tcx.mk_region(ty::ReErased),
+ |_, _| tcx.types.re_erased,
|def, _| tcx.mk_param_from_def(def));
let fty = tcx.mk_fn_def(def_id, substs, ty::Binder(tcx.mk_fn_sig(
// In general, during probing we erase regions. See
// `impl_self_ty()` for an explanation.
- let region = tcx.mk_region(ty::ReErased);
+ let region = tcx.types.re_erased;
// Search through mutabilities in order to find one where pick works:
[hir::MutImmutable, hir::MutMutable]
} else {
// In general, during probe we erase regions. See
// `impl_self_ty()` for an explanation.
- self.tcx.mk_region(ty::ReErased)
+ self.tcx.types.re_erased
}
}, |def, cur_substs| {
let i = def.index as usize;
let substs = Substs::for_item(self.tcx,
impl_def_id,
- |_, _| self.tcx.mk_region(ty::ReErased),
+ |_, _| self.tcx.types.re_erased,
|_, _| self.next_ty_var(
TypeVariableOrigin::SubstitutionPlaceholder(
self.tcx.def_span(impl_def_id))));
//
// FIXME(#27579) all uses of this should be migrated to register_wf_obligation eventually
let cause = traits::ObligationCause::new(span, self.body_id, code);
- self.register_region_obligation(ty, self.tcx.mk_region(ty::ReEmpty), cause);
+ self.register_region_obligation(ty, self.tcx.types.re_empty, cause);
}
/// Registers obligations that all types appearing in `substs` are well-formed.
match lit.node {
ast::LitKind::Str(..) => tcx.mk_static_str(),
ast::LitKind::ByteStr(ref v) => {
- tcx.mk_imm_ref(tcx.mk_region(ty::ReStatic),
+ tcx.mk_imm_ref(tcx.types.re_static,
tcx.mk_array(tcx.types.u8, v.len()))
}
ast::LitKind::Byte(_) => tcx.types.u8,
let outside_ty = gcx.fold_regions(&inside_ty, &mut false, |r, _| {
match *r {
// 'static is valid everywhere.
- ty::ReStatic |
- ty::ReEmpty => gcx.mk_region(*r),
+ ty::ReStatic => gcx.types.re_static,
+ ty::ReEmpty => gcx.types.re_empty,
// Free regions that come from early-bound regions are valid.
ty::ReFree(ty::FreeRegion {
span_err!(self.tcx().sess, span, E0564,
"only named lifetimes are allowed in `impl Trait`, \
but `{}` was found in the type `{}`", r, inside_ty);
- gcx.mk_region(ty::ReStatic)
+ gcx.types.re_static
}
ty::ReVar(_) |
match self.infcx.fully_resolve(&r) {
Ok(r) => r,
Err(_) => {
- self.tcx.mk_region(ty::ReStatic)
+ self.tcx.types.re_static
}
}
}