Skip to content

Commit 47e0803

Browse files
committed
Auto merge of rust-lang#60195 - varkor:commontypes-to-common, r=eddyb
Split `CommonTypes` into `CommonTypes` and `CommonLifetimes` The so-called "`CommonTypes`" contains more than just types. r? @eddyb
2 parents 834bd19 + 7261bd8 commit 47e0803

File tree

31 files changed

+82
-68
lines changed

31 files changed

+82
-68
lines changed

src/librustc/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for TypeFreshener<'a, 'gcx, 'tcx> {
101101
ty::ReEmpty |
102102
ty::ReErased => {
103103
// replace all free regions with 'erased
104-
self.tcx().types.re_erased
104+
self.tcx().lifetimes.re_erased
105105
}
106106

107107
ty::ReClosureBound(..) => {

src/librustc/infer/lexical_region_resolve/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
138138
/// empty region. The `expansion` phase will grow this larger.
139139
fn construct_var_data(&self, tcx: TyCtxt<'_, '_, 'tcx>) -> LexicalRegionResolutions<'tcx> {
140140
LexicalRegionResolutions {
141-
error_region: tcx.types.re_static,
142-
values: IndexVec::from_elem_n(VarValue::Value(tcx.types.re_empty), self.num_vars())
141+
error_region: tcx.lifetimes.re_static,
142+
values: IndexVec::from_elem_n(VarValue::Value(tcx.lifetimes.re_empty), self.num_vars())
143143
}
144144
}
145145

@@ -266,7 +266,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
266266
let b_universe = self.var_infos[b_vid].universe;
267267
if let ty::RePlaceholder(p) = lub {
268268
if b_universe.cannot_name(p.universe) {
269-
lub = self.tcx().types.re_static;
269+
lub = self.tcx().lifetimes.re_static;
270270
}
271271
}
272272

@@ -348,7 +348,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
348348

349349
// otherwise, we don't know what the free region is,
350350
// so we must conservatively say the LUB is static:
351-
tcx.types.re_static
351+
tcx.lifetimes.re_static
352352
}
353353

354354
(&ReScope(a_id), &ReScope(b_id)) => {
@@ -371,7 +371,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
371371
(&RePlaceholder(..), _) | (_, &RePlaceholder(..)) => if a == b {
372372
a
373373
} else {
374-
tcx.types.re_static
374+
tcx.lifetimes.re_static
375375
},
376376
}
377377
}
@@ -598,7 +598,7 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
598598
for lower_bound in &lower_bounds {
599599
let effective_lower_bound = if let ty::RePlaceholder(p) = lower_bound.region {
600600
if node_universe.cannot_name(p.universe) {
601-
self.tcx().types.re_static
601+
self.tcx().lifetimes.re_static
602602
} else {
603603
lower_bound.region
604604
}

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
370370
}
371371
}
372372

373-
let least_region = least_region.unwrap_or(self.tcx.types.re_static);
373+
let least_region = least_region.unwrap_or(self.tcx.lifetimes.re_static);
374374
debug!("constrain_opaque_types: least_region={:?}", least_region);
375375

376376
// Require that the type `concrete_ty` outlives
@@ -608,7 +608,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
608608
err.emit();
609609
}
610610
}
611-
self.tcx.types.re_empty
611+
self.tcx.lifetimes.re_empty
612612
},
613613
}
614614
}

src/librustc/middle/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
434434

435435
hir::ExprKind::Match(ref discr, ref arms, _) => {
436436
let discr_cmt = Rc::new(return_if_err!(self.mc.cat_expr(&discr)));
437-
let r = self.tcx().types.re_empty;
437+
let r = self.tcx().lifetimes.re_empty;
438438
self.borrow_expr(&discr, r, ty::ImmBorrow, MatchDiscriminant);
439439

440440
// treatment of the discriminant is handled while walking the arms.

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
965965
// we can promote to a constant, otherwise equal to enclosing temp
966966
// lifetime.
967967
let re = if promotable {
968-
self.tcx.types.re_static
968+
self.tcx.lifetimes.re_static
969969
} else {
970970
self.temporary_scope(hir_id.local_id)
971971
};

src/librustc/traits/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
787787
(None, Some(t_a)) => {
788788
select.infcx().register_region_obligation_with_cause(
789789
t_a,
790-
select.infcx().tcx.types.re_static,
790+
select.infcx().tcx.lifetimes.re_static,
791791
&dummy_cause,
792792
);
793793
}

src/librustc/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
359359
// `for<'a> T: 'a where 'a not in T`, which we can treat as
360360
// `T: 'static`.
361361
Some(t_a) => {
362-
let r_static = self.selcx.tcx().types.re_static;
362+
let r_static = self.selcx.tcx().lifetimes.re_static;
363363
if self.register_region_obligations {
364364
self.selcx.infcx().register_region_obligation_with_cause(
365365
t_a,

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ fn vtable_methods<'a, 'tcx>(
10101010
let substs = trait_ref.map_bound(|trait_ref|
10111011
InternalSubsts::for_item(tcx, def_id, |param, _|
10121012
match param.kind {
1013-
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
1013+
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
10141014
GenericParamDefKind::Type { .. } |
10151015
GenericParamDefKind::Const => {
10161016
trait_ref.substs[param.index as usize]

src/librustc/ty/context.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ pub struct CommonTypes<'tcx> {
225225
/// a trait object, and which gets removed in `ExistentialTraitRef`.
226226
/// This type must not appear anywhere in other converted types.
227227
pub trait_object_dummy_self: Ty<'tcx>,
228+
}
228229

230+
pub struct CommonLifetimes<'tcx> {
229231
pub re_empty: Region<'tcx>,
230232
pub re_static: Region<'tcx>,
231233
pub re_erased: Region<'tcx>,
@@ -935,11 +937,6 @@ EnumLiftImpl! {
935937
impl<'tcx> CommonTypes<'tcx> {
936938
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
937939
let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
938-
let mk_region = |r| {
939-
interners.region.borrow_mut().intern(r, |r| {
940-
Interned(interners.arena.alloc(r))
941-
}).0
942-
};
943940

944941
CommonTypes {
945942
unit: mk(Tuple(List::empty())),
@@ -963,10 +960,22 @@ impl<'tcx> CommonTypes<'tcx> {
963960
f64: mk(Float(ast::FloatTy::F64)),
964961

965962
trait_object_dummy_self: mk(Infer(ty::FreshTy(0))),
963+
}
964+
}
965+
}
966966

967-
re_empty: mk_region(RegionKind::ReEmpty),
968-
re_static: mk_region(RegionKind::ReStatic),
969-
re_erased: mk_region(RegionKind::ReErased),
967+
impl<'tcx> CommonLifetimes<'tcx> {
968+
fn new(interners: &CtxtInterners<'tcx>) -> CommonLifetimes<'tcx> {
969+
let mk = |r| {
970+
interners.region.borrow_mut().intern(r, |r| {
971+
Interned(interners.arena.alloc(r))
972+
}).0
973+
};
974+
975+
CommonLifetimes {
976+
re_empty: mk(RegionKind::ReEmpty),
977+
re_static: mk(RegionKind::ReStatic),
978+
re_erased: mk(RegionKind::ReErased),
970979
}
971980
}
972981
}
@@ -1018,6 +1027,9 @@ pub struct GlobalCtxt<'tcx> {
10181027
/// Common types, pre-interned for your convenience.
10191028
pub types: CommonTypes<'tcx>,
10201029

1030+
/// Common lifetimes, pre-interned for your convenience.
1031+
pub lifetimes: CommonLifetimes<'tcx>,
1032+
10211033
/// Map indicating what traits are in scope for places where this
10221034
/// is relevant; generated by resolve.
10231035
trait_map: FxHashMap<DefIndex,
@@ -1216,6 +1228,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12161228
});
12171229
let interners = CtxtInterners::new(&arenas.interner);
12181230
let common_types = CommonTypes::new(&interners);
1231+
let common_lifetimes = CommonLifetimes::new(&interners);
12191232
let dep_graph = hir.dep_graph.clone();
12201233
let max_cnum = cstore.crates_untracked().iter().map(|c| c.as_usize()).max().unwrap_or(0);
12211234
let mut providers = IndexVec::from_elem_n(extern_providers, max_cnum + 1);
@@ -1270,6 +1283,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
12701283
global_interners: interners,
12711284
dep_graph,
12721285
types: common_types,
1286+
lifetimes: common_lifetimes,
12731287
trait_map,
12741288
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
12751289
let exports: Vec<_> = v.into_iter().map(|e| {
@@ -2468,7 +2482,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24682482

24692483
#[inline]
24702484
pub fn mk_static_str(self) -> Ty<'tcx> {
2471-
self.mk_imm_ref(self.types.re_static, self.mk_str())
2485+
self.mk_imm_ref(self.lifetimes.re_static, self.mk_str())
24722486
}
24732487

24742488
#[inline]

src/librustc/ty/erase_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionEraserVisitor<'a, 'gcx, 't
6767
// whenever a substitution occurs.
6868
match *r {
6969
ty::ReLateBound(..) => r,
70-
_ => self.tcx.types.re_erased
70+
_ => self.tcx.lifetimes.re_erased
7171
}
7272
}
7373
}

0 commit comments

Comments
 (0)