Skip to content

Commit 59a4f02

Browse files
committed
Auto merge of #127438 - compiler-errors:compute-outlives-visitor, r=lcnr
Make `push_outlives_components` into a `TypeVisitor` This involves removing the `visited: &mut SsoHashSet<GenericArg<'tcx>>` that is being passed around the `VerifyBoundCx`. The fact that we were using it when decomposing different type tests seems sketchy, so I don't think, though it may technically result in us registering more redundant outlives components 🤷 I did end up deleting some of the comments that referred back to RFC 1214 during this refactor. I can add them back if you think they were useful. r? lcnr
2 parents 7fdefb8 + c895985 commit 59a4f02

File tree

3 files changed

+127
-247
lines changed

3 files changed

+127
-247
lines changed

compiler/rustc_infer/src/infer/outlives/obligations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ where
471471
// projection outlive; in some cases, this may add insufficient
472472
// edges into the inference graph, leading to inference failures
473473
// even though a satisfactory solution exists.
474-
let verify_bound = self.verify_bound.alias_bound(alias_ty, &mut Default::default());
474+
let verify_bound = self.verify_bound.alias_bound(alias_ty);
475475
debug!("alias_must_outlive: pushing {:?}", verify_bound);
476476
self.delegate.push_verify(origin, GenericKind::Alias(alias_ty), region, verify_bound);
477477
}

compiler/rustc_infer/src/infer/outlives/verify.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use crate::infer::outlives::env::RegionBoundPairs;
22
use crate::infer::region_constraints::VerifyIfEq;
33
use crate::infer::{GenericKind, VerifyBound};
4-
use rustc_data_structures::sso::SsoHashSet;
5-
use rustc_middle::ty::GenericArg;
64
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
75
use rustc_type_ir::outlives::{compute_alias_components_recursive, Component};
86

@@ -99,12 +97,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9997
self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
10098
}
10199

102-
#[instrument(level = "debug", skip(self, visited))]
103-
pub fn alias_bound(
104-
&self,
105-
alias_ty: ty::AliasTy<'tcx>,
106-
visited: &mut SsoHashSet<GenericArg<'tcx>>,
107-
) -> VerifyBound<'tcx> {
100+
#[instrument(level = "debug", skip(self))]
101+
pub fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
108102
let alias_ty_as_ty = alias_ty.to_ty(self.tcx);
109103

110104
// Search the env for where clauses like `P: 'a`.
@@ -130,21 +124,17 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
130124
// see the extensive comment in projection_must_outlive
131125
let recursive_bound = {
132126
let mut components = smallvec![];
133-
compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components, visited);
134-
self.bound_from_components(&components, visited)
127+
compute_alias_components_recursive(self.tcx, alias_ty_as_ty, &mut components);
128+
self.bound_from_components(&components)
135129
};
136130

137131
VerifyBound::AnyBound(env_bounds.chain(definition_bounds).collect()).or(recursive_bound)
138132
}
139133

140-
fn bound_from_components(
141-
&self,
142-
components: &[Component<TyCtxt<'tcx>>],
143-
visited: &mut SsoHashSet<GenericArg<'tcx>>,
144-
) -> VerifyBound<'tcx> {
134+
fn bound_from_components(&self, components: &[Component<TyCtxt<'tcx>>]) -> VerifyBound<'tcx> {
145135
let mut bounds = components
146136
.iter()
147-
.map(|component| self.bound_from_single_component(component, visited))
137+
.map(|component| self.bound_from_single_component(component))
148138
// Remove bounds that must hold, since they are not interesting.
149139
.filter(|bound| !bound.must_hold());
150140

@@ -159,18 +149,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
159149
fn bound_from_single_component(
160150
&self,
161151
component: &Component<TyCtxt<'tcx>>,
162-
visited: &mut SsoHashSet<GenericArg<'tcx>>,
163152
) -> VerifyBound<'tcx> {
164153
match *component {
165154
Component::Region(lt) => VerifyBound::OutlivedBy(lt),
166155
Component::Param(param_ty) => self.param_or_placeholder_bound(param_ty.to_ty(self.tcx)),
167156
Component::Placeholder(placeholder_ty) => {
168157
self.param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty))
169158
}
170-
Component::Alias(alias_ty) => self.alias_bound(alias_ty, visited),
171-
Component::EscapingAlias(ref components) => {
172-
self.bound_from_components(components, visited)
173-
}
159+
Component::Alias(alias_ty) => self.alias_bound(alias_ty),
160+
Component::EscapingAlias(ref components) => self.bound_from_components(components),
174161
Component::UnresolvedInferenceVariable(v) => {
175162
// Ignore this, we presume it will yield an error later, since
176163
// if a type variable is not resolved by this point it never

0 commit comments

Comments
 (0)