Skip to content

Rollup of 7 pull requests #139536

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

Merged
merged 20 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
1862b31
rm `RegionInferenceContext::var_infos`
lcnr Apr 7, 2025
42048ea
compiletest: Cleanup collection of actual errors
petrochenkov Apr 7, 2025
b86b3fb
compiletest: Always preserve kind for compiler diagnostics
petrochenkov Apr 7, 2025
5c160f5
compiletest: Stricter parsing for diagnostic kinds
petrochenkov Apr 7, 2025
fd854a7
compiletest: Avoid ignoring empty diagnostics in one more place
petrochenkov Apr 7, 2025
2fb550b
Update books
rustbot Apr 7, 2025
4aab8e8
document panic behavior of Vec::resize and Vec::resize_with
jogru0 Apr 7, 2025
b08e9c2
Fix stack overflow in exhaustiveness due to recursive HIR opaque type…
compiler-errors Apr 7, 2025
01e44b1
add missing word in doc comment
tshepang Apr 8, 2025
8501dcb
remove unusual indentation
tshepang Apr 8, 2025
c7272a6
clean code: remove Deref<Target=RegionKind> impl for Region and use `…
xizheyin Apr 8, 2025
a8b0eb7
Update compiler/rustc_borrowck/src/diagnostics/region_errors.rs
xizheyin Apr 8, 2025
c66d35e
update if let to match in universal_regions.rs
xizheyin Apr 8, 2025
75f3bd6
Rollup merge of #139476 - lcnr:rm-var_infos, r=compiler-errors
matthiaskrgr Apr 8, 2025
df57bdf
Rollup merge of #139485 - petrochenkov:errkind-light, r=oli-obk,jieyouxu
matthiaskrgr Apr 8, 2025
7bc1d3a
Rollup merge of #139491 - rustbot:docs-update, r=ehuss
matthiaskrgr Apr 8, 2025
890c6de
Rollup merge of #139500 - jogru0:117437, r=tgross35
matthiaskrgr Apr 8, 2025
9ea9339
Rollup merge of #139501 - compiler-errors:suppress-stack-overflow, r=…
matthiaskrgr Apr 8, 2025
74c2a9b
Rollup merge of #139504 - tshepang:patch-5, r=jieyouxu
matthiaskrgr Apr 8, 2025
1cbf8b5
Rollup merge of #139509 - xizheyin:issue-139359, r=lcnr
matthiaskrgr Apr 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
// started MIR borrowchecking with, so the region
// constraints have already been taken. Use the data from
// our `mbcx` instead.
|vid| mbcx.regioncx.var_infos[vid].origin,
|vid| mbcx.regioncx.var_infos[vid].universe,
|vid| RegionVariableOrigin::Nll(mbcx.regioncx.definitions[vid].origin),
|vid| mbcx.regioncx.definitions[vid].universe,
)
}
}
Expand Down Expand Up @@ -487,7 +487,7 @@ fn try_extract_error_from_region_constraints<'a, 'tcx>(
let (sub_region, cause) = info?;

debug!(?sub_region, "cause = {:#?}", cause);
let error = match (error_region, *sub_region) {
let error = match (error_region, sub_region.kind()) {
(Some(error_region), ty::ReVar(vid)) => RegionResolutionError::SubSupConflict(
vid,
region_var_origin(vid),
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use rustc_errors::{Applicability, Diag, EmissionGuarantee, MultiSpan, listify};
use rustc_hir::def::{CtorKind, Namespace};
use rustc_hir::{self as hir, CoroutineKind, LangItem};
use rustc_index::IndexSlice;
use rustc_infer::infer::{
BoundRegionConversionTime, NllRegionVariableOrigin, RegionVariableOrigin,
};
use rustc_infer::infer::{BoundRegionConversionTime, NllRegionVariableOrigin};
use rustc_infer::traits::SelectionError;
use rustc_middle::bug;
use rustc_middle::mir::{
Expand Down Expand Up @@ -587,7 +585,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
// this by hooking into the pretty printer and telling it to label the
// lifetimes without names with the value `'0`.
if let ty::Ref(region, ..) = ty.kind() {
match **region {
match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand All @@ -607,7 +605,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS);

let region = if let ty::Ref(region, ..) = ty.kind() {
match **region {
match region.kind() {
ty::ReBound(_, ty::BoundRegion { kind: br, .. })
| ty::RePlaceholder(ty::PlaceholderRegion {
bound: ty::BoundRegion { kind: br, .. },
Expand All @@ -633,9 +631,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
) {
let predicate_span = path.iter().find_map(|constraint| {
let outlived = constraint.sub;
if let Some(origin) = self.regioncx.var_infos.get(outlived)
&& let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(_)) =
origin.origin
if let Some(origin) = self.regioncx.definitions.get(outlived)
&& let NllRegionVariableOrigin::Placeholder(_) = origin.origin
&& let ConstraintCategory::Predicate(span) = constraint.category
{
Some(span)
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,16 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
fold_regions(tcx, ty, |region, _| match *region {
fold_regions(tcx, ty, |region, _| match region.kind() {
ty::ReVar(vid) => self.to_error_region(vid).unwrap_or(region),
_ => region,
})
}

/// Returns `true` if a closure is inferred to be an `FnMut` closure.
fn is_closure_fn_mut(&self, fr: RegionVid) -> bool {
if let Some(ty::ReLateParam(late_param)) = self.to_error_region(fr).as_deref()
if let Some(r) = self.to_error_region(fr)
&& let ty::ReLateParam(late_param) = r.kind()
&& let ty::LateParamRegionKind::ClosureEnv = late_param.kind
&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
{
Expand Down Expand Up @@ -832,7 +833,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
if let (Some(f), Some(outlived_f)) =
(self.to_error_region(fr), self.to_error_region(outlived_fr))
{
if *outlived_f != ty::ReStatic {
if outlived_f.kind() != ty::ReStatic {
return;
}
let suitable_region = self.infcx.tcx.is_suitable_region(self.mir_def_id(), f);
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
let tcx = self.infcx.tcx;

debug!("give_region_a_name: error_region = {:?}", error_region);
match *error_region {
match error_region.kind() {
ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
Expand Down Expand Up @@ -896,7 +896,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self,
fr: RegionVid,
) -> Option<RegionName> {
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
return None;
};
if region.has_name() {
Expand All @@ -912,7 +912,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {

let found = tcx
.any_free_region_meets(&tcx.type_of(region_parent).instantiate_identity(), |r| {
*r == ty::ReEarlyParam(region)
r.kind() == ty::ReEarlyParam(region)
});

Some(RegionName {
Expand All @@ -931,7 +931,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
&self,
fr: RegionVid,
) -> Option<RegionName> {
let ty::ReEarlyParam(region) = *self.to_error_region(fr)? else {
let ty::ReEarlyParam(region) = self.to_error_region(fr)?.kind() else {
return None;
};
if region.has_name() {
Expand Down Expand Up @@ -1007,7 +1007,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
if data.projection_term.self_ty() == ty => {}
_ => return false,
}
tcx.any_free_region_meets(pred, |r| *r == ty::ReEarlyParam(region))
tcx.any_free_region_meets(pred, |r| r.kind() == ty::ReEarlyParam(region))
})
} else {
false
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ fn emit_mermaid_nll_regions<'tcx>(
writeln!(out, "flowchart TD")?;

// Emit the region nodes.
for region in regioncx.var_infos.indices() {
for region in regioncx.definitions.indices() {
write!(out, "{}[\"", region.as_usize())?;
render_region(region, regioncx, out)?;
writeln!(out, "\"]")?;
Expand Down Expand Up @@ -387,7 +387,7 @@ fn emit_mermaid_nll_sccs<'tcx>(
// Gather and emit the SCC nodes.
let mut nodes_per_scc: IndexVec<_, _> =
regioncx.constraint_sccs().all_sccs().map(|_| Vec::new()).collect();
for region in regioncx.var_infos.indices() {
for region in regioncx.definitions.indices() {
let scc = regioncx.constraint_sccs().scc(region);
nodes_per_scc[scc].push(region);
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,11 @@ impl RegionTracker {
}

pub struct RegionInferenceContext<'tcx> {
pub var_infos: VarInfos,

/// Contains the definition for every region variable. Region
/// variables are identified by their index (`RegionVid`). The
/// definition contains information about where the region came
/// from as well as its final inferred value.
definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
pub(crate) definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,

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

let mut result = Self {
var_infos,
definitions,
liveness_constraints,
constraints,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
fold_regions(tcx, ty, |region, _| match *region {
fold_regions(tcx, ty, |region, _| match region.kind() {
ty::ReVar(vid) => {
let scc = self.constraint_sccs.scc(vid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
/// are dealt with during trait solving.
fn replace_placeholders_with_nll<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
if value.has_placeholders() {
fold_regions(self.tcx, value, |r, _| match *r {
fold_regions(self.tcx, value, |r, _| match r.kind() {
ty::RePlaceholder(placeholder) => {
self.constraints.placeholder_region(self.infcx, placeholder)
}
Expand All @@ -227,7 +227,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
}

fn to_region_vid(&mut self, r: ty::Region<'tcx>) -> ty::RegionVid {
if let ty::RePlaceholder(placeholder) = *r {
if let ty::RePlaceholder(placeholder) = r.kind() {
self.constraints.placeholder_region(self.infcx, placeholder).as_var()
} else {
self.universal_regions.to_region_vid(r)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/type_check/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ where
}

fn visit_region(&mut self, r: ty::Region<'tcx>) {
match *r {
match r.kind() {
// ignore bound regions, keep visiting
ty::ReBound(_, _) => {}
_ => (self.op)(r),
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,19 +909,19 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// if it is a placeholder. Handling placeholders requires access to the
/// `MirTypeckRegionConstraints`.
fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
if let ty::ReVar(..) = *r {
r.as_var()
} else if let ty::ReError(guar) = *r {
self.tainted_by_errors.set(Some(guar));
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
// errors are being emitted and 2) it leaves the happy path unaffected.
self.fr_static
} else {
*self
match r.kind() {
ty::ReVar(..) => r.as_var(),
ty::ReError(guar) => {
self.tainted_by_errors.set(Some(guar));
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
// errors are being emitted and 2) it leaves the happy path unaffected.
self.fr_static
}
_ => *self
.indices
.get(&r)
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r))
.unwrap_or_else(|| bug!("cannot convert `{:?}` to a region vid", r)),
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for RemapLateParam<'tcx> {
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
if let ty::ReLateParam(fr) = *r {
if let ty::ReLateParam(fr) = r.kind() {
ty::Region::new_late_param(
self.tcx,
fr.scope,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Ignore `'static` lifetimes for the purpose of this lint: it's
// because we know it outlives everything and so doesn't give meaningful
// clues. Also ignore `ReError`, to avoid knock-down errors.
if let ty::ReStatic | ty::ReError(_) = **region_a {
if let ty::ReStatic | ty::ReError(_) = region_a.kind() {
continue;
}
// For each region argument (e.g., `'a` in our example), check for a
Expand Down Expand Up @@ -672,7 +672,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
// Again, skip `'static` because it outlives everything. Also, we trivially
// know that a region outlives itself. Also ignore `ReError`, to avoid
// knock-down errors.
if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b {
if matches!(region_b.kind(), ty::ReStatic | ty::ReError(_)) || region_a == region_b {
continue;
}
if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/coherence/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ fn infringing_fields_error<'tcx>(
.entry((ty.clone(), predicate.clone()))
.or_default()
.push(origin.span());
if let ty::RegionKind::ReEarlyParam(ebr) = *b
if let ty::RegionKind::ReEarlyParam(ebr) = b.kind()
&& ebr.has_name()
{
bounds.push((b.to_string(), a.to_string(), None));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ fn recover_infer_ret_ty<'tcx>(
GenericParamKind::Lifetime { .. } => true,
_ => false,
});
let fn_sig = fold_regions(tcx, fn_sig, |r, _| match *r {
let fn_sig = fold_regions(tcx, fn_sig, |r, _| match r.kind() {
ty::ReErased => {
if has_region_params {
ty::Region::new_error_with_message(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn compute_bidirectional_outlives_predicates<'tcx>(
) {
for param in opaque_own_params {
let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local());
if let ty::ReEarlyParam(..) = *orig_lifetime {
if let ty::ReEarlyParam(..) = orig_lifetime.kind() {
let dup_lifetime = ty::Region::new_early_param(
tcx,
ty::EarlyParamRegion { index: param.index, name: param.name },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
}

fn visit_region(&mut self, r: ty::Region<'tcx>) {
if let ty::ReEarlyParam(data) = *r {
if let ty::ReEarlyParam(data) = r.kind() {
self.parameters.push(Parameter::from(data));
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(

fn is_free_region(region: Region<'_>) -> bool {
// First, screen for regions that might appear in a type header.
match *region {
match region.kind() {
// These correspond to `T: 'a` relationships:
//
// struct Foo<'a, T> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
region: ty::Region<'tcx>,
variance: VarianceTermPtr<'a>,
) {
match *region {
match region.kind() {
ty::ReEarlyParam(ref data) => {
self.add_constraint(current, data.index, variance);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
) -> ty::Region<'tcx> {
let infcx = canonicalizer.infcx.unwrap();

if let ty::ReVar(vid) = *r {
if let ty::ReVar(vid) = r.kind() {
r = infcx
.inner
.borrow_mut()
Expand All @@ -171,7 +171,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
);
};

match *r {
match r.kind() {
ty::ReLateParam(_) | ty::ReErased | ty::ReStatic | ty::ReEarlyParam(..) => r,

ty::RePlaceholder(placeholder) => canonicalizer.canonical_var_for_region(
Expand Down Expand Up @@ -227,7 +227,7 @@ impl CanonicalizeMode for CanonicalizeUserTypeAnnotation {
canonicalizer: &mut Canonicalizer<'_, 'tcx>,
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
match *r {
match r.kind() {
ty::ReEarlyParam(_)
| ty::ReLateParam(_)
| ty::ReErased
Expand Down Expand Up @@ -321,7 +321,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
match r.kind() {
ty::ReBound(index, ..) => {
if index >= self.binder_index {
bug!("escaping late-bound region during canonicalization");
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl<'tcx> InferCtxt<'tcx> {
}
GenericArgKind::Lifetime(result_value) => {
// e.g., here `result_value` might be `'?1` in the example above...
if let ty::ReBound(debruijn, br) = *result_value {
if let ty::ReBound(debruijn, br) = result_value.kind() {
// ... in which case we would set `canonical_vars[0]` to `Some('static)`.

// We only allow a `ty::INNERMOST` index in generic parameters.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
match r.kind() {
ty::ReBound(..) => {
// leave bound regions alone
r
Expand Down
Loading
Loading