Skip to content

Commit b258537

Browse files
committed
Auto merge of rust-lang#139536 - matthiaskrgr:rollup-j6goald, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#139476 (rm `RegionInferenceContext::var_infos`) - rust-lang#139485 (compiletest: Stricter parsing for diagnostic kinds) - rust-lang#139491 (Update books) - rust-lang#139500 (document panic behavior of Vec::resize and Vec::resize_with) - rust-lang#139501 (Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types) - rust-lang#139504 (add missing word in doc comment) - rust-lang#139509 (clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d4f880f + 1cbf8b5 commit b258537

File tree

89 files changed

+531
-305
lines changed

Some content is hidden

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

89 files changed

+531
-305
lines changed

compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
406406
// started MIR borrowchecking with, so the region
407407
// constraints have already been taken. Use the data from
408408
// our `mbcx` instead.
409-
|vid| mbcx.regioncx.var_infos[vid].origin,
410-
|vid| mbcx.regioncx.var_infos[vid].universe,
409+
|vid| RegionVariableOrigin::Nll(mbcx.regioncx.definitions[vid].origin),
410+
|vid| mbcx.regioncx.definitions[vid].universe,
411411
)
412412
}
413413
}
@@ -487,7 +487,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
487487
let (sub_region, cause) = info?;
488488

489489
debug!(?sub_region, "cause = {:#?}", cause);
490-
let error = match (error_region, *sub_region) {
490+
let error = match (error_region, sub_region.kind()) {
491491
(Some(error_region), ty::ReVar(vid)) => RegionResolutionError::SubSupConflict(
492492
vid,
493493
region_var_origin(vid),

compiler/rustc_borrowck/src/diagnostics/mod.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
88
use rustc_hir::def::{CtorKind, Namespace};
99
use rustc_hir::{self as hir, CoroutineKind, LangItem};
1010
use rustc_index::IndexSlice;
11-
use rustc_infer::infer::{
12-
BoundRegionConversionTime, NllRegionVariableOrigin, RegionVariableOrigin,
13-
};
11+
use rustc_infer::infer::{BoundRegionConversionTime, NllRegionVariableOrigin};
1412
use rustc_infer::traits::SelectionError;
1513
use rustc_middle::bug;
1614
use rustc_middle::mir::{
@@ -587,7 +585,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
587585
// this by hooking into the pretty printer and telling it to label the
588586
// lifetimes without names with the value `'0`.
589587
if let ty::Ref(region, ..) = ty.kind() {
590-
match **region {
588+
match region.kind() {
591589
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
592590
| ty::RePlaceholder(ty::PlaceholderRegion {
593591
bound: ty::BoundRegion { kind: br, .. },
@@ -607,7 +605,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
607605
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);
608606

609607
let region = if let ty::Ref(region, ..) = ty.kind() {
610-
match **region {
608+
match region.kind() {
611609
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
612610
| ty::RePlaceholder(ty::PlaceholderRegion {
613611
bound: ty::BoundRegion { kind: br, .. },
@@ -633,9 +631,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
633631
) {
634632
let predicate_span = path.iter().find_map(|constraint| {
635633
let outlived = constraint.sub;
636-
if let Some(origin) = self.regioncx.var_infos.get(outlived)
637-
&& let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(_)) =
638-
origin.origin
634+
if let Some(origin) = self.regioncx.definitions.get(outlived)
635+
&& let NllRegionVariableOrigin::Placeholder(_) = origin.origin
639636
&& let ConstraintCategory::Predicate(span) = constraint.category
640637
{
641638
Some(span)

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
190190
where
191191
T: TypeFoldable<TyCtxt<'tcx>>,
192192
{
193-
fold_regions(tcx, ty, |region, _| match *region {
193+
fold_regions(tcx, ty, |region, _| match region.kind() {
194194
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
195195
_ => region,
196196
})
197197
}
198198

199199
/// Returns `true` if a closure is inferred to be an `FnMut` closure.
200200
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
201-
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
201+
if let Some(r) = self.to_error_region(fr)
202+
&& let ty::ReLateParam(late_param) = r.kind()
202203
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind
203204
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
204205
{
@@ -832,7 +833,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
832833
if let (Some(f), Some(outlived_f)) =
833834
(self.to_error_region(fr), self.to_error_region(outlived_fr))
834835
{
835-
if *outlived_f != ty::ReStatic {
836+
if outlived_f.kind() != ty::ReStatic {
836837
return;
837838
}
838839
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
288288
let tcx = self.infcx.tcx;
289289

290290
debug!("give_region_a_name: error_region = {:?}", error_region);
291-
match *error_region {
291+
match error_region.kind() {
292292
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
293293
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
294294
let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
@@ -896,7 +896,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
896896
&self,
897897
fr: RegionVid,
898898
) -> Option<RegionName> {
899-
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
899+
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
900900
return None;
901901
};
902902
if region.has_name() {
@@ -912,7 +912,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
912912

913913
let found = tcx
914914
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
915-
*r == ty::ReEarlyParam(region)
915+
r.kind() == ty::ReEarlyParam(region)
916916
});
917917

918918
Some(RegionName {
@@ -931,7 +931,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
931931
&self,
932932
fr: RegionVid,
933933
) -> Option<RegionName> {
934-
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
934+
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
935935
return None;
936936
};
937937
if region.has_name() {
@@ -1007,7 +1007,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
10071007
if data.projection_term.self_ty() == ty => {}
10081008
_ => return false,
10091009
}
1010-
tcx.any_free_region_meets(pred, |r| *r == ty::ReEarlyParam(region))
1010+
tcx.any_free_region_meets(pred, |r| r.kind() == ty::ReEarlyParam(region))
10111011
})
10121012
} else {
10131013
false

compiler/rustc_borrowck/src/polonius/dump.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ fn emit_mermaid_nll_regions<'tcx>(
334334
writeln!(out, "flowchart TD")?;
335335

336336
// Emit the region nodes.
337-
for region in regioncx.var_infos.indices() {
337+
for region in regioncx.definitions.indices() {
338338
write!(out, "{}[\"", region.as_usize())?;
339339
render_region(region, regioncx, out)?;
340340
writeln!(out, "\"]")?;
@@ -387,7 +387,7 @@ fn emit_mermaid_nll_sccs<'tcx>(
387387
// Gather and emit the SCC nodes.
388388
let mut nodes_per_scc: IndexVec<_, _> =
389389
regioncx.constraint_sccs().all_sccs().map(|_| Vec::new()).collect();
390-
for region in regioncx.var_infos.indices() {
390+
for region in regioncx.definitions.indices() {
391391
let scc = regioncx.constraint_sccs().scc(region);
392392
nodes_per_scc[scc].push(region);
393393
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,11 @@ impl RegionTracker {
141141
}
142142

143143
pub struct RegionInferenceContext<'tcx> {
144-
pub var_infos: VarInfos,
145-
146144
/// Contains the definition for every region variable. Region
147145
/// variables are identified by their index (`RegionVid`). The
148146
/// definition contains information about where the region came
149147
/// from as well as its final inferred value.
150-
definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
148+
pub(crate) definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
151149

152150
/// The liveness constraints added to each region. For most
153151
/// regions, these start out empty and steadily grow, though for
@@ -455,7 +453,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
455453
Rc::new(member_constraints.into_mapped(|r| constraint_sccs.scc(r)));
456454

457455
let mut result = Self {
458-
var_infos,
459456
definitions,
460457
liveness_constraints,
461458
constraints,

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
186186
where
187187
T: TypeFoldable<TyCtxt<'tcx>>,
188188
{
189-
fold_regions(tcx, ty, |region, _| match *region {
189+
fold_regions(tcx, ty, |region, _| match region.kind() {
190190
ty::ReVar(vid) => {
191191
let scc = self.constraint_sccs.scc(vid);
192192

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
205205
/// are dealt with during trait solving.
206206
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
207207
if value.has_placeholders() {
208-
fold_regions(self.tcx, value, |r, _| match *r {
208+
fold_regions(self.tcx, value, |r, _| match r.kind() {
209209
ty::RePlaceholder(placeholder) => {
210210
self.constraints.placeholder_region(self.infcx, placeholder)
211211
}
@@ -227,7 +227,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
227227
}
228228

229229
fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
230-
if let ty::RePlaceholder(placeholder) = *r {
230+
if let ty::RePlaceholder(placeholder) = r.kind() {
231231
self.constraints.placeholder_region(self.infcx, placeholder).as_var()
232232
} else {
233233
self.universal_regions.to_region_vid(r)

compiler/rustc_borrowck/src/type_check/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ where
271271
}
272272

273273
fn visit_region(&mut self, r: ty::Region<'tcx>) {
274-
match *r {
274+
match r.kind() {
275275
// ignore bound regions, keep visiting
276276
ty::ReBound(_, _) => {}
277277
_ => (self.op)(r),

compiler/rustc_borrowck/src/universal_regions.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -909,19 +909,19 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
909909
/// if it is a placeholder. Handling placeholders requires access to the
910910
/// `MirTypeckRegionConstraints`.
911911
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
912-
if let ty::ReVar(..) = *r {
913-
r.as_var()
914-
} else if let ty::ReError(guar) = *r {
915-
self.tainted_by_errors.set(Some(guar));
916-
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
917-
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
918-
// errors are being emitted and 2) it leaves the happy path unaffected.
919-
self.fr_static
920-
} else {
921-
*self
912+
match r.kind() {
913+
ty::ReVar(..) => r.as_var(),
914+
ty::ReError(guar) => {
915+
self.tainted_by_errors.set(Some(guar));
916+
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
917+
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
918+
// errors are being emitted and 2) it leaves the happy path unaffected.
919+
self.fr_static
920+
}
921+
_ => *self
922922
.indices
923923
.get(&r)
924-
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))
924+
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r)),
925925
}
926926
}
927927

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
442442
}
443443

444444
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
445-
if let ty::ReLateParam(fr) = *r {
445+
if let ty::ReLateParam(fr) = r.kind() {
446446
ty::Region::new_late_param(
447447
self.tcx,
448448
fr.scope,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
631631
// Ignore `'static` lifetimes for the purpose of this lint: it's
632632
// because we know it outlives everything and so doesn't give meaningful
633633
// clues. Also ignore `ReError`, to avoid knock-down errors.
634-
if let ty::ReStatic | ty::ReError(_) = **region_a {
634+
if let ty::ReStatic | ty::ReError(_) = region_a.kind() {
635635
continue;
636636
}
637637
// For each region argument (e.g., `'a` in our example), check for a
@@ -672,7 +672,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
672672
// Again, skip `'static` because it outlives everything. Also, we trivially
673673
// know that a region outlives itself. Also ignore `ReError`, to avoid
674674
// knock-down errors.
675-
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
675+
if matches!(region_b.kind(), ty::ReStatic | ty::ReError(_)) || region_a == region_b {
676676
continue;
677677
}
678678
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ fn infringing_fields_error<'tcx>(
656656
.entry((ty.clone(), predicate.clone()))
657657
.or_default()
658658
.push(origin.span());
659-
if let ty::RegionKind::ReEarlyParam(ebr) = *b
659+
if let ty::RegionKind::ReEarlyParam(ebr) = b.kind()
660660
&& ebr.has_name()
661661
{
662662
bounds.push((b.to_string(), a.to_string(), None));

compiler/rustc_hir_analysis/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1416,7 +1416,7 @@ fn recover_infer_ret_ty<'tcx>(
14161416
GenericParamKind::Lifetime { .. } => true,
14171417
_ => false,
14181418
});
1419-
let fn_sig = fold_regions(tcx, fn_sig, |r, _| match *r {
1419+
let fn_sig = fold_regions(tcx, fn_sig, |r, _| match r.kind() {
14201420
ty::ReErased => {
14211421
if has_region_params {
14221422
ty::Region::new_error_with_message(

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
359359
) {
360360
for param in opaque_own_params {
361361
let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
362-
if let ty::ReEarlyParam(..) = *orig_lifetime {
362+
if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
363363
let dup_lifetime = ty::Region::new_early_param(
364364
tcx,
365365
ty::EarlyParamRegion { index: param.index, name: param.name },

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
8080
}
8181

8282
fn visit_region(&mut self, r: ty::Region<'tcx>) {
83-
if let ty::ReEarlyParam(data) = *r {
83+
if let ty::ReEarlyParam(data) = r.kind() {
8484
self.parameters.push(Parameter::from(data));
8585
}
8686
}

compiler/rustc_hir_analysis/src/outlives/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
146146

147147
fn is_free_region(region: Region<'_>) -> bool {
148148
// First, screen for regions that might appear in a type header.
149-
match *region {
149+
match region.kind() {
150150
// These correspond to `T: 'a` relationships:
151151
//
152152
// struct Foo<'a, T> {

compiler/rustc_hir_analysis/src/variance/constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
428428
region: ty::Region<'tcx>,
429429
variance: VarianceTermPtr<'a>,
430430
) {
431-
match *region {
431+
match region.kind() {
432432
ty::ReEarlyParam(ref data) => {
433433
self.add_constraint(current, data.index, variance);
434434
}

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
159159
) -> ty::Region<'tcx> {
160160
let infcx = canonicalizer.infcx.unwrap();
161161

162-
if let ty::ReVar(vid) = *r {
162+
if let ty::ReVar(vid) = r.kind() {
163163
r = infcx
164164
.inner
165165
.borrow_mut()
@@ -171,7 +171,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
171171
);
172172
};
173173

174-
match *r {
174+
match r.kind() {
175175
ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r,
176176

177177
ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
@@ -227,7 +227,7 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
227227
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
228228
r: ty::Region<'tcx>,
229229
) -> ty::Region<'tcx> {
230-
match *r {
230+
match r.kind() {
231231
ty::ReEarlyParam(_)
232232
| ty::ReLateParam(_)
233233
| ty::ReErased
@@ -321,7 +321,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
321321
}
322322

323323
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
324-
match *r {
324+
match r.kind() {
325325
ty::ReBound(index, ..) => {
326326
if index >= self.binder_index {
327327
bug!("escaping late-bound region during canonicalization");

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'tcx> InferCtxt<'tcx> {
432432
}
433433
GenericArgKind::Lifetime(result_value) => {
434434
// e.g., here `result_value` might be `'?1` in the example above...
435-
if let ty::ReBound(debruijn, br) = *result_value {
435+
if let ty::ReBound(debruijn, br) = result_value.kind() {
436436
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.
437437

438438
// We only allow a `ty::INNERMOST` index in generic parameters.

compiler/rustc_infer/src/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
109109
}
110110

111111
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
112-
match *r {
112+
match r.kind() {
113113
ty::ReBound(..) => {
114114
// leave bound regions alone
115115
r

0 commit comments

Comments
 (0)