Skip to content

(More) consistently use "region" terminology in rustc_middle #110621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
@@ -1047,7 +1047,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
type_known_to_meet_bound_modulo_regions(
&infcx,
self.param_env,
tcx.mk_imm_ref(tcx.lifetimes.re_erased, tcx.erase_regions(ty)),
tcx.mk_imm_ref(tcx.regions.erased, tcx.erase_regions(ty)),
def_id,
)
}
6 changes: 2 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
@@ -597,7 +597,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
) -> Option<&'hir hir::Lifetime> {
for (kind, hir_arg) in iter::zip(substs, args.args) {
match (kind.unpack(), hir_arg) {
(GenericArgKind::Lifetime(r), hir::GenericArg::Lifetime(lt)) => {
(GenericArgKind::Region(r), hir::GenericArg::Lifetime(lt)) => {
if r.as_var() == needle_fr {
return Some(lt);
}
@@ -613,9 +613,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}

(
GenericArgKind::Lifetime(_)
| GenericArgKind::Type(_)
| GenericArgKind::Const(_),
GenericArgKind::Region(_) | GenericArgKind::Type(_) | GenericArgKind::Const(_),
_,
) => {
// HIR lowering sometimes doesn't catch this in erroneous
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
@@ -1114,8 +1114,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
let substs =
std::iter::zip(substs, tcx.variances_of(def_id)).map(|(arg, v)| {
match (arg.unpack(), v) {
(ty::GenericArgKind::Lifetime(_), ty::Bivariant) => {
tcx.lifetimes.re_static.into()
(ty::GenericArgKind::Region(_), ty::Bivariant) => {
tcx.regions.re_static.into()
}
_ => arg.fold_with(self),
}
@@ -1142,7 +1142,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.map(|u_r| tcx.mk_re_var(u_r))
// In the case of a failure, use `ReErased`. We will eventually
// return `None` in this case.
.unwrap_or(tcx.lifetimes.re_erased)
.unwrap_or(tcx.regions.erased)
});

debug!("try_promote_type_test_subject: folded ty = {:?}", ty);
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
.iter()
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)
.unwrap_or(infcx.tcx.lifetimes.re_erased),
.unwrap_or(infcx.tcx.regions.erased),
_ => region,
});
debug!(?universal_concrete_type);
@@ -367,8 +367,8 @@ fn check_opaque_type_parameter_valid(
for (i, arg) in opaque_type_key.substs.iter().enumerate() {
let arg_is_param = match arg.unpack() {
GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(_)),
GenericArgKind::Lifetime(lt) => {
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
GenericArgKind::Region(re) => {
matches!(*re, ty::ReEarlyBound(_) | ty::ReFree(_))
}
GenericArgKind::Const(ct) => matches!(ct.kind(), ty::ConstKind::Param(_)),
};
Original file line number Diff line number Diff line change
@@ -141,7 +141,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {

let ty::OutlivesPredicate(k1, r2) = predicate;
match k1.unpack() {
GenericArgKind::Lifetime(r1) => {
GenericArgKind::Region(r1) => {
let r1_vid = self.to_region_vid(r1);
let r2_vid = self.to_region_vid(r2);
self.add_outlives(r1_vid, r2_vid, constraint_category);
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
@@ -248,7 +248,7 @@ impl<'tcx> UniversalRegions<'tcx> {
closure_def_id: LocalDefId,
) -> IndexVec<RegionVid, ty::Region<'tcx>> {
let mut region_mapping = IndexVec::with_capacity(expected_num_vars);
region_mapping.push(tcx.lifetimes.re_static);
region_mapping.push(tcx.regions.re_static);
tcx.for_each_free_region(&closure_substs, |fr| {
region_mapping.push(fr);
});
@@ -632,7 +632,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
DefiningTy::FnDef(_, substs) | DefiningTy::Const(_, substs) => substs,
};

let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
let global_mapping = iter::once((tcx.regions.re_static, fr_static));
let subst_mapping =
iter::zip(identity_substs.regions(), fr_substs.regions().map(|r| r.as_var()));

2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
@@ -668,7 +668,7 @@ pub(crate) fn codegen_drop<'tcx>(
let arg_value = drop_place.place_ref(
fx,
fx.layout_of(fx.tcx.mk_ref(
fx.tcx.lifetimes.re_erased,
fx.tcx.regions.erased,
TypeAndMut { ty, mutbl: crate::rustc_hir::Mutability::Mut },
)),
);
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
@@ -187,8 +187,8 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
let instance = Instance::new(
def_id,
InternalSubsts::for_item(tcx, def_id, |param, _| {
if let ty::GenericParamDefKind::Lifetime = param.kind {
tcx.lifetimes.re_erased.into()
if let ty::GenericParamDefKind::Region = param.kind {
tcx.regions.erased.into()
} else {
tcx.mk_param_from_def(param)
}
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
@@ -573,7 +573,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Rvalue::Ref(_, bk, place) => {
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ref(
tcx.lifetimes.re_erased,
tcx.regions.erased,
ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() },
)
};
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let loc_ty = self
.tcx
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
.subst(*self.tcx, self.tcx.mk_substs(&[self.tcx.lifetimes.re_erased.into()]));
.subst(*self.tcx, self.tcx.mk_substs(&[self.tcx.regions.erased.into()]));
let loc_layout = self.layout_of(loc_ty).unwrap();
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();

7 changes: 3 additions & 4 deletions compiler/rustc_const_eval/src/interpret/place.rs
Original file line number Diff line number Diff line change
@@ -775,10 +775,9 @@ where
let meta = Scalar::from_target_usize(u64::try_from(str.len()).unwrap(), self);
let mplace = MemPlace { ptr: ptr.into(), meta: MemPlaceMeta::Meta(meta) };

let ty = self.tcx.mk_ref(
self.tcx.lifetimes.re_static,
ty::TypeAndMut { ty: self.tcx.types.str_, mutbl },
);
let ty = self
.tcx
.mk_ref(self.tcx.regions.re_static, ty::TypeAndMut { ty: self.tcx.types.str_, mutbl });
let layout = self.layout_of(ty).unwrap();
Ok(MPlaceTy { mplace, layout, align: layout.align.abi })
}
Original file line number Diff line number Diff line change
@@ -346,7 +346,7 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {

// No constraints on lifetimes or constants, except potentially
// constants' types, but `walk` will get to them as well.
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue,
GenericArgKind::Region(_) | GenericArgKind::Const(_) => continue,
};

match *ty.kind() {
6 changes: 3 additions & 3 deletions compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
@@ -859,11 +859,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
let span = statement.source_info.span;

let ref_ty = tcx.mk_ref(
tcx.lifetimes.re_erased,
tcx.regions.erased,
ty::TypeAndMut { ty, mutbl: borrow_kind.to_mutbl_lossy() },
);

*region = tcx.lifetimes.re_erased;
*region = tcx.regions.erased;

let mut projection = vec![PlaceElem::Deref];
projection.extend(place.projection);
@@ -887,7 +887,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
self.extra_statements.push((loc, promoted_ref_statement));

Rvalue::Ref(
tcx.lifetimes.re_erased,
tcx.regions.erased,
*borrow_kind,
Place {
local: mem::replace(&mut place.local, promoted_ref),
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
) -> Result<Self::Path, Self::Error> {
self = print_prefix(self)?;
let args =
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Region(_)));
if args.clone().next().is_some() {
self.generic_delimiters(|cx| cx.comma_sep(args))
} else {
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/astconv/generics.rs
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
match (args.peek(), params.peek()) {
(Some(&arg), Some(&param)) => {
match (arg, &param.kind, arg_count.explicit_late_bound) {
(GenericArg::Lifetime(_), GenericParamDefKind::Lifetime, _)
(GenericArg::Lifetime(_), GenericParamDefKind::Region, _)
| (
GenericArg::Type(_) | GenericArg::Infer(_),
GenericParamDefKind::Type { .. },
@@ -259,7 +259,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>(
}
(
GenericArg::Infer(_) | GenericArg::Type(_) | GenericArg::Const(_),
GenericParamDefKind::Lifetime,
GenericParamDefKind::Region,
_,
) => {
// We expected a lifetime argument, but got a type or const
20 changes: 10 additions & 10 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
@@ -229,7 +229,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let lifetime_name = |def_id| tcx.hir().name(tcx.hir().local_def_id_to_hir_id(def_id));

match tcx.named_bound_var(lifetime.hir_id) {
Some(rbv::ResolvedArg::StaticLifetime) => tcx.lifetimes.re_static,
Some(rbv::ResolvedArg::StaticLifetime) => tcx.regions.re_static,

Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => {
let name = lifetime_name(def_id.expect_local());
@@ -437,7 +437,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
};

match (&param.kind, arg) {
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
(GenericParamDefKind::Region, GenericArg::Lifetime(lt)) => {
self.astconv.ast_region_to_region(lt, Some(param)).into()
}
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
@@ -481,7 +481,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
) -> subst::GenericArg<'tcx> {
let tcx = self.astconv.tcx();
match param.kind {
GenericParamDefKind::Lifetime => self
GenericParamDefKind::Region => self
.astconv
.re_infer(Some(param), self.span)
.unwrap_or_else(|| {
@@ -1175,7 +1175,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let substs =
candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
let subst = match param.kind {
GenericParamDefKind::Lifetime => tcx
GenericParamDefKind::Region => tcx
.mk_re_late_bound(
ty::INNERMOST,
ty::BoundRegion {
@@ -2340,7 +2340,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let self_ty = tcx.replace_escaping_bound_vars_uncached(
self_ty,
FnMutDelegate {
regions: &mut |_| tcx.lifetimes.re_erased,
regions: &mut |_| tcx.regions.erased,
types: &mut |bv| {
tcx.mk_placeholder(ty::PlaceholderType { universe, bound: bv })
},
@@ -2520,7 +2520,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx,
infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id),
);
let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
let value = tcx.fold_regions(qself_ty, |_, _| tcx.regions.erased);
// FIXME: Don't bother dealing with non-lifetime binders here...
if value.has_escaping_bound_vars() {
return false;
@@ -3227,7 +3227,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
hir::TyKind::Typeof(e) => {
let ty_erased = tcx.type_of(e.def_id).subst_identity();
let ty = tcx.fold_regions(ty_erased, |r, _| {
if r.is_erased() { tcx.lifetimes.re_static } else { r }
if r.is_erased() { tcx.regions.re_static } else { r }
});
let span = ast_ty.span;
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
@@ -3274,7 +3274,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if let Some(i) = (param.index as usize).checked_sub(generics.count() - lifetimes.len())
{
// Resolve our own lifetime parameters.
let GenericParamDefKind::Lifetime { .. } = param.kind else { bug!() };
let GenericParamDefKind::Region { .. } = param.kind else { bug!() };
let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] else { bug!() };
self.ast_region_to_region(lifetime, None).into()
} else {
@@ -3519,7 +3519,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// If any of the derived region bounds are 'static, that is always
// the best choice.
if derived_region_bounds.iter().any(|r| r.is_static()) {
return Some(tcx.lifetimes.re_static);
return Some(tcx.regions.re_static);
}

// Determine whether there is exactly one unique region in the set
@@ -3651,7 +3651,7 @@ pub trait InferCtxtExt<'tcx> {
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx> {
InternalSubsts::for_item(self.tcx, def_id, |param, _| match param.kind {
GenericParamDefKind::Lifetime => self.tcx.lifetimes.re_erased.into(),
GenericParamDefKind::Region => self.tcx.regions.erased.into(),
GenericParamDefKind::Type { .. } => self
.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::SubstitutionPlaceholder,
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
@@ -1429,11 +1429,11 @@ fn compare_synthetic_generics<'tcx>(
let trait_m_generics = tcx.generics_of(trait_m.def_id);
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| match param.kind {
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
GenericParamDefKind::Region | GenericParamDefKind::Const { .. } => None,
});
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| match param.kind {
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
GenericParamDefKind::Lifetime | GenericParamDefKind::Const { .. } => None,
GenericParamDefKind::Region | GenericParamDefKind::Const { .. } => None,
});
for ((impl_def_id, impl_synthetic), (trait_def_id, trait_synthetic)) in
iter::zip(impl_m_type_params, trait_m_type_params)
@@ -1599,7 +1599,7 @@ fn compare_generic_param_kinds<'tcx>(
// this is exhaustive so that anyone adding new generic param kinds knows
// to make sure this error is reported for them.
(Const { .. }, Const { .. }) | (Type { .. }, Type { .. }) => false,
(Lifetime { .. }, _) | (_, Lifetime { .. }) => unreachable!(),
(Region { .. }, _) | (_, Region { .. }) => unreachable!(),
} {
let param_impl_span = tcx.def_span(param_impl.def_id);
let param_trait_span = tcx.def_span(param_trait.def_id);
@@ -1623,7 +1623,7 @@ fn compare_generic_param_kinds<'tcx>(
)
}
Type { .. } => format!("{} type parameter", prefix),
Lifetime { .. } => unreachable!(),
Region { .. } => unreachable!(),
};

let trait_header_span = tcx.def_ident_span(tcx.parent(trait_item.def_id)).unwrap();
@@ -1916,7 +1916,7 @@ pub(super) fn check_type_bounds<'tcx>(
)
.into()
}
GenericParamDefKind::Lifetime => {
GenericParamDefKind::Region => {
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
let bound_var = ty::BoundVariableKind::Region(kind);
bound_vars.push(bound_var);
10 changes: 5 additions & 5 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
@@ -718,8 +718,8 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATSubstCollector<'tcx> {
ty::Alias(ty::Projection, p) if p.def_id == self.gat => {
for (idx, subst) in p.substs.iter().enumerate() {
match subst.unpack() {
GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => {
self.regions.insert((lt, idx));
GenericArgKind::Region(re) if !re.is_late_bound() => {
self.regions.insert((re, idx));
}
GenericArgKind::Type(t) => {
self.types.insert((t, idx));
@@ -1273,7 +1273,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
| GenericParamDefKind::Const { has_default } => {
has_default && def.index >= generics.parent_count as u32
}
GenericParamDefKind::Lifetime => unreachable!(),
GenericParamDefKind::Region => unreachable!(),
};

// Check that concrete defaults are well-formed. See test `type-check-defaults.rs`.
@@ -1316,7 +1316,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
}
}
// Doesn't have defaults.
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Region => {}
}
}

@@ -1330,7 +1330,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
// First we build the defaulted substitution.
let substs = InternalSubsts::for_item(tcx, def_id.to_def_id(), |param, _| {
match param.kind {
GenericParamDefKind::Lifetime => {
GenericParamDefKind::Region => {
// All regions are identity.
tcx.mk_param_from_def(param)
}
Loading