Skip to content

Make push_outlives_components into a TypeVisitor #127438

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 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/obligations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ where
// projection outlive; in some cases, this may add insufficient
// edges into the inference graph, leading to inference failures
// even though a satisfactory solution exists.
let verify_bound = self.verify_bound.alias_bound(alias_ty, &mut Default::default());
let verify_bound = self.verify_bound.alias_bound(alias_ty);
debug!("alias_must_outlive: pushing {:?}", verify_bound);
self.delegate.push_verify(origin, GenericKind::Alias(alias_ty), region, verify_bound);
}
Expand Down
29 changes: 8 additions & 21 deletions compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::infer::outlives::env::RegionBoundPairs;
use crate::infer::region_constraints::VerifyIfEq;
use crate::infer::{GenericKind, VerifyBound};
use rustc_data_structures::sso::SsoHashSet;
use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
use rustc_type_ir::outlives::{compute_alias_components_recursive, Component};

Expand Down Expand Up @@ -99,12 +97,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
}

#[instrument(level = "debug", skip(self, visited))]
pub fn alias_bound(
&self,
alias_ty: ty::AliasTy<'tcx>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
#[instrument(level = "debug", skip(self))]
pub fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
let alias_ty_as_ty = alias_ty.to_ty(self.tcx);

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

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

fn bound_from_components(
&self,
components: &[Component<TyCtxt<'tcx>>],
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
fn bound_from_components(&self, components: &[Component<TyCtxt<'tcx>>]) -> VerifyBound<'tcx> {
let mut bounds = components
.iter()
.map(|component| self.bound_from_single_component(component, visited))
.map(|component| self.bound_from_single_component(component))
// Remove bounds that must hold, since they are not interesting.
.filter(|bound| !bound.must_hold());

Expand All @@ -159,18 +149,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
fn bound_from_single_component(
&self,
component: &Component<TyCtxt<'tcx>>,
visited: &mut SsoHashSet<GenericArg<'tcx>>,
) -> VerifyBound<'tcx> {
match *component {
Component::Region(lt) => VerifyBound::OutlivedBy(lt),
Component::Param(param_ty) => self.param_or_placeholder_bound(param_ty.to_ty(self.tcx)),
Component::Placeholder(placeholder_ty) => {
self.param_or_placeholder_bound(Ty::new_placeholder(self.tcx, placeholder_ty))
}
Component::Alias(alias_ty) => self.alias_bound(alias_ty, visited),
Component::EscapingAlias(ref components) => {
self.bound_from_components(components, visited)
}
Component::Alias(alias_ty) => self.alias_bound(alias_ty),
Component::EscapingAlias(ref components) => self.bound_from_components(components),
Component::UnresolvedInferenceVariable(v) => {
// Ignore this, we presume it will yield an error later, since
// if a type variable is not resolved by this point it never
Expand Down
Loading
Loading