Skip to content

Commit 45eec0f

Browse files
committed
Auto merge of rust-lang#112075 - WaffleLapkin:unmkII, r=lcnr
Replace `tcx.mk_re_*` with `Region::new_*` Second step in implementing rust-lang/compiler-team#616 r? `@lcnr`
2 parents 165cdda + e33e208 commit 45eec0f

File tree

42 files changed

+292
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+292
-234
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,25 @@ trait TypeOpInfo<'tcx> {
180180
return;
181181
};
182182

183-
let placeholder_region = tcx.mk_re_placeholder(ty::Placeholder {
184-
universe: adjusted_universe.into(),
185-
bound: placeholder.bound,
186-
});
187-
188-
let error_region =
189-
if let RegionElement::PlaceholderRegion(error_placeholder) = error_element {
190-
let adjusted_universe =
191-
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
192-
adjusted_universe.map(|adjusted| {
193-
tcx.mk_re_placeholder(ty::Placeholder {
194-
universe: adjusted.into(),
195-
bound: error_placeholder.bound,
196-
})
197-
})
198-
} else {
199-
None
200-
};
183+
let placeholder_region = ty::Region::new_placeholder(
184+
tcx,
185+
ty::Placeholder { universe: adjusted_universe.into(), bound: placeholder.bound },
186+
);
187+
188+
let error_region = if let RegionElement::PlaceholderRegion(error_placeholder) =
189+
error_element
190+
{
191+
let adjusted_universe =
192+
error_placeholder.universe.as_u32().checked_sub(base_universe.as_u32());
193+
adjusted_universe.map(|adjusted| {
194+
ty::Region::new_placeholder(
195+
tcx,
196+
ty::Placeholder { universe: adjusted.into(), bound: error_placeholder.bound },
197+
)
198+
})
199+
} else {
200+
None
201+
};
201202

202203
debug!(?placeholder_region);
203204

@@ -390,7 +391,7 @@ fn try_extract_error_from_fulfill_cx<'tcx>(
390391
error_region,
391392
&region_constraints,
392393
|vid| ocx.infcx.region_var_origin(vid),
393-
|vid| ocx.infcx.universe_of_region(ocx.infcx.tcx.mk_re_var(vid)),
394+
|vid| ocx.infcx.universe_of_region(ty::Region::new_var(ocx.infcx.tcx, vid)),
394395
)
395396
}
396397

@@ -411,7 +412,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
411412
}
412413
// FIXME: Should this check the universe of the var?
413414
Constraint::VarSubReg(vid, sup) if sup == placeholder_region => {
414-
Some((infcx.tcx.mk_re_var(vid), cause.clone()))
415+
Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))
415416
}
416417
_ => None,
417418
}

compiler/rustc_borrowck/src/nll.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn for_each_region_constraint<'tcx>(
441441
let subject = match req.subject {
442442
ClosureOutlivesSubject::Region(subject) => format!("{:?}", subject),
443443
ClosureOutlivesSubject::Ty(ty) => {
444-
format!("{:?}", ty.instantiate(tcx, |vid| tcx.mk_re_var(vid)))
444+
format!("{:?}", ty.instantiate(tcx, |vid| ty::Region::new_var(tcx, vid)))
445445
}
446446
};
447447
with_msg(format!("where {}: {:?}", subject, req.outlived_free_region,))?;

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11581158
.universal_regions_outlived_by(r_scc)
11591159
.filter(|&u_r| !self.universal_regions.is_local_free_region(u_r))
11601160
.find(|&u_r| self.eval_equal(u_r, r_vid))
1161-
.map(|u_r| tcx.mk_re_var(u_r))
1161+
.map(|u_r| ty::Region::new_var(tcx, u_r))
11621162
// In the case of a failure, use `ReErased`. We will eventually
11631163
// return `None` in this case.
11641164
.unwrap_or(tcx.lifetimes.re_erased)
@@ -1355,7 +1355,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13551355
let vid = self.to_region_vid(r);
13561356
let scc = self.constraint_sccs.scc(vid);
13571357
let repr = self.scc_representatives[scc];
1358-
tcx.mk_re_var(repr)
1358+
ty::Region::new_var(tcx, repr)
13591359
})
13601360
}
13611361

@@ -1779,7 +1779,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17791779
}
17801780

17811781
// If not, report an error.
1782-
let member_region = infcx.tcx.mk_re_var(member_region_vid);
1782+
let member_region = ty::Region::new_var(infcx.tcx, member_region_vid);
17831783
errors_buffer.push(RegionErrorKind::UnexpectedHiddenRegion {
17841784
span: m_c.definition_span,
17851785
hidden_ty: m_c.hidden_ty,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9292
}
9393
None => {
9494
subst_regions.push(vid);
95-
infcx.tcx.mk_re_error_with_message(
95+
ty::Region::new_error_with_message(
96+
infcx.tcx,
9697
concrete_type.span,
9798
"opaque type with non-universal region substs",
9899
)

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
139139
upvars: &[Upvar<'tcx>],
140140
use_polonius: bool,
141141
) -> MirTypeckResults<'tcx> {
142-
let implicit_region_bound = infcx.tcx.mk_re_var(universal_regions.fr_fn_body);
142+
let implicit_region_bound = ty::Region::new_var(infcx.tcx, universal_regions.fr_fn_body);
143143
let mut constraints = MirTypeckRegionConstraints {
144144
placeholder_indices: PlaceholderIndices::default(),
145145
placeholder_index_to_region: IndexVec::default(),

compiler/rustc_borrowck/src/universal_regions.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
500500
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("c-variadic")))
501501
.as_var();
502502

503-
let region = self.infcx.tcx.mk_re_var(reg_vid);
503+
let region = ty::Region::new_var(self.infcx.tcx, reg_vid);
504504
let va_list_ty =
505505
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
506506

@@ -660,7 +660,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
660660
var: ty::BoundVar::from_usize(bound_vars.len() - 1),
661661
kind: ty::BrEnv,
662662
};
663-
let env_region = tcx.mk_re_late_bound(ty::INNERMOST, br);
663+
let env_region = ty::Region::new_late_bound(tcx, ty::INNERMOST, br);
664664
let closure_ty = tcx.closure_env_ty(def_id, substs, env_region).unwrap();
665665

666666
// The "inputs" of the closure in the
@@ -778,7 +778,8 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
778778
{
779779
let (value, _map) = self.tcx.replace_late_bound_regions(value, |br| {
780780
debug!(?br);
781-
let liberated_region = self.tcx.mk_re_free(all_outlive_scope.to_def_id(), br.kind);
781+
let liberated_region =
782+
ty::Region::new_free(self.tcx, all_outlive_scope.to_def_id(), br.kind);
782783
let region_vid = {
783784
let name = match br.kind.get_name() {
784785
Some(name) => name,
@@ -889,7 +890,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
889890
where
890891
T: TypeFoldable<TyCtxt<'tcx>>,
891892
{
892-
tcx.fold_regions(value, |region, _| tcx.mk_re_var(self.to_region_vid(region)))
893+
tcx.fold_regions(value, |region, _| ty::Region::new_var(tcx, self.to_region_vid(region)))
893894
}
894895
}
895896

@@ -929,7 +930,7 @@ fn for_each_late_bound_region_in_item<'tcx>(
929930

930931
for bound_var in tcx.late_bound_vars(tcx.hir().local_def_id_to_hir_id(mir_def_id)) {
931932
let ty::BoundVariableKind::Region(bound_region) = bound_var else { continue; };
932-
let liberated_region = tcx.mk_re_free(mir_def_id.to_def_id(), bound_region);
933+
let liberated_region = ty::Region::new_free(tcx, mir_def_id.to_def_id(), bound_region);
933934
f(liberated_region);
934935
}
935936
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+17-15
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,20 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
239239
var: ty::BoundVar::from_u32(index),
240240
kind: ty::BrNamed(def_id, name),
241241
};
242-
tcx.mk_re_late_bound(debruijn, br)
242+
ty::Region::new_late_bound(tcx, debruijn, br)
243243
}
244244

245245
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
246246
let name = tcx.hir().ty_param_name(def_id.expect_local());
247247
let item_def_id = tcx.hir().ty_param_owner(def_id.expect_local());
248248
let generics = tcx.generics_of(item_def_id);
249249
let index = generics.param_def_id_to_index[&def_id];
250-
tcx.mk_re_early_bound(ty::EarlyBoundRegion { def_id, index, name })
250+
ty::Region::new_early_bound(tcx, ty::EarlyBoundRegion { def_id, index, name })
251251
}
252252

253253
Some(rbv::ResolvedArg::Free(scope, id)) => {
254254
let name = lifetime_name(id.expect_local());
255-
tcx.mk_re_free(scope, ty::BrNamed(id, name))
255+
ty::Region::new_free(tcx, scope, ty::BrNamed(id, name))
256256

257257
// (*) -- not late-bound, won't change
258258
}
@@ -269,7 +269,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
269269
// elision. `resolve_lifetime` should have
270270
// reported an error in this case -- but if
271271
// not, let's error out.
272-
tcx.mk_re_error_with_message(
272+
ty::Region::new_error_with_message(
273+
tcx,
273274
lifetime.ident.span,
274275
"unelided lifetime in signature",
275276
)
@@ -485,7 +486,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
485486
debug!(?param, "unelided lifetime in signature");
486487

487488
// This indicates an illegal lifetime in a non-assoc-trait position
488-
tcx.mk_re_error_with_message(
489+
ty::Region::new_error_with_message(
490+
tcx,
489491
self.span,
490492
"unelided lifetime in signature",
491493
)
@@ -1219,15 +1221,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
12191221
let substs =
12201222
candidate.skip_binder().substs.extend_to(tcx, assoc_item.def_id, |param, _| {
12211223
let subst = match param.kind {
1222-
GenericParamDefKind::Lifetime => tcx
1223-
.mk_re_late_bound(
1224-
ty::INNERMOST,
1225-
ty::BoundRegion {
1226-
var: ty::BoundVar::from_usize(num_bound_vars),
1227-
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
1228-
},
1229-
)
1230-
.into(),
1224+
GenericParamDefKind::Lifetime => ty::Region::new_late_bound(
1225+
tcx,
1226+
ty::INNERMOST,
1227+
ty::BoundRegion {
1228+
var: ty::BoundVar::from_usize(num_bound_vars),
1229+
kind: ty::BoundRegionKind::BrNamed(param.def_id, param.name),
1230+
},
1231+
)
1232+
.into(),
12311233
GenericParamDefKind::Type { .. } => tcx
12321234
.mk_bound(
12331235
ty::INNERMOST,
@@ -1804,7 +1806,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
18041806
} else {
18051807
err.emit()
18061808
};
1807-
tcx.mk_re_error(e)
1809+
ty::Region::new_error(tcx, e)
18081810
})
18091811
}
18101812
})

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateBound<'_, 'tcx> {
472472

473473
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
474474
if let ty::ReFree(fr) = *r {
475-
self.tcx.mk_re_free(
475+
ty::Region::new_free(
476+
self.tcx,
476477
fr.scope,
477478
self.mapping.get(&fr.bound_region).copied().unwrap_or(fr.bound_region),
478479
)
@@ -786,9 +787,9 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
786787
}
787788
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
788789
else {
789-
return tcx.mk_re_error_with_message(return_span, "expected ReFree to map to ReEarlyBound")
790+
return ty::Region::new_error_with_message(tcx, return_span, "expected ReFree to map to ReEarlyBound")
790791
};
791-
tcx.mk_re_early_bound(ty::EarlyBoundRegion {
792+
ty::Region::new_early_bound(tcx, ty::EarlyBoundRegion {
792793
def_id: e.def_id,
793794
name: e.name,
794795
index: (e.index as usize - num_trait_substs + num_impl_substs) as u32,
@@ -1933,7 +1934,8 @@ pub(super) fn check_type_bounds<'tcx>(
19331934
let kind = ty::BoundRegionKind::BrNamed(param.def_id, param.name);
19341935
let bound_var = ty::BoundVariableKind::Region(kind);
19351936
bound_vars.push(bound_var);
1936-
tcx.mk_re_late_bound(
1937+
ty::Region::new_late_bound(
1938+
tcx,
19371939
ty::INNERMOST,
19381940
ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind },
19391941
)

compiler/rustc_hir_analysis/src/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
183183
}
184184
RegionResolutionError::SubSupConflict(_, _, _, a, _, b, _) => format!("{b}: {a}"),
185185
RegionResolutionError::UpperBoundUniverseConflict(a, _, _, _, b) => {
186-
format!("{b}: {a}", a = tcx.mk_re_var(a))
186+
format!("{b}: {a}", a = ty::Region::new_var(tcx, a))
187187
}
188188
};
189189
guar = Some(

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
145145
]);
146146
let mk_va_list_ty = |mutbl| {
147147
tcx.lang_items().va_list().map(|did| {
148-
let region = tcx.mk_re_late_bound(
148+
let region = ty::Region::new_late_bound(
149+
tcx,
149150
ty::INNERMOST,
150151
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
151152
);
152-
let env_region = tcx.mk_re_late_bound(
153+
let env_region = ty::Region::new_late_bound(
154+
tcx,
153155
ty::INNERMOST,
154156
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
155157
);
@@ -393,7 +395,12 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
393395
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
394396
(
395397
1,
396-
vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))],
398+
vec![
399+
tcx.mk_imm_ref(
400+
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),
401+
param(0),
402+
),
403+
],
397404
tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])),
398405
)
399406
}
@@ -443,7 +450,8 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
443450

444451
sym::raw_eq => {
445452
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
446-
let param_ty = tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0));
453+
let param_ty =
454+
tcx.mk_imm_ref(ty::Region::new_late_bound(tcx, ty::INNERMOST, br), param(0));
447455
(1, vec![param_ty; 2], tcx.types.bool)
448456
}
449457

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,14 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
556556
// Same for the region. In our example, 'a corresponds
557557
// to the 'me parameter.
558558
let region_param = gat_generics.param_at(*region_a_idx, tcx);
559-
let region_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
560-
def_id: region_param.def_id,
561-
index: region_param.index,
562-
name: region_param.name,
563-
});
559+
let region_param = ty::Region::new_early_bound(
560+
tcx,
561+
ty::EarlyBoundRegion {
562+
def_id: region_param.def_id,
563+
index: region_param.index,
564+
name: region_param.name,
565+
},
566+
);
564567
// The predicate we expect to see. (In our example,
565568
// `Self: 'me`.)
566569
let clause = ty::PredicateKind::Clause(ty::Clause::TypeOutlives(
@@ -593,18 +596,24 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
593596
debug!("required clause: {region_a} must outlive {region_b}");
594597
// Translate into the generic parameters of the GAT.
595598
let region_a_param = gat_generics.param_at(*region_a_idx, tcx);
596-
let region_a_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
597-
def_id: region_a_param.def_id,
598-
index: region_a_param.index,
599-
name: region_a_param.name,
600-
});
599+
let region_a_param = ty::Region::new_early_bound(
600+
tcx,
601+
ty::EarlyBoundRegion {
602+
def_id: region_a_param.def_id,
603+
index: region_a_param.index,
604+
name: region_a_param.name,
605+
},
606+
);
601607
// Same for the region.
602608
let region_b_param = gat_generics.param_at(*region_b_idx, tcx);
603-
let region_b_param = tcx.mk_re_early_bound(ty::EarlyBoundRegion {
604-
def_id: region_b_param.def_id,
605-
index: region_b_param.index,
606-
name: region_b_param.name,
607-
});
609+
let region_b_param = ty::Region::new_early_bound(
610+
tcx,
611+
ty::EarlyBoundRegion {
612+
def_id: region_b_param.def_id,
613+
index: region_b_param.index,
614+
name: region_b_param.name,
615+
},
616+
);
608617
// The predicate we expect to see.
609618
let clause = ty::PredicateKind::Clause(ty::Clause::RegionOutlives(
610619
ty::OutlivesPredicate(region_a_param, region_b_param),

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
440440
self.tcx.replace_late_bound_regions_uncached(
441441
poly_trait_ref,
442442
|_| {
443-
self.tcx.mk_re_early_bound(ty::EarlyBoundRegion {
443+
ty::Region::new_early_bound(self.tcx, ty::EarlyBoundRegion {
444444
def_id: item_def_id,
445445
index: 0,
446446
name: Symbol::intern(&lt_name),

0 commit comments

Comments
 (0)