Move push_outlives_components to rustc_infer
This commit is contained in:
parent
1dafe6d1c3
commit
a7c132de55
7 changed files with 23 additions and 21 deletions
|
@ -2,10 +2,10 @@
|
||||||
// refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
|
// refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
|
||||||
// RFC for reference.
|
// RFC for reference.
|
||||||
|
|
||||||
use crate::ty::subst::{GenericArg, GenericArgKind};
|
|
||||||
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
|
|
||||||
use rustc_data_structures::sso::SsoHashSet;
|
use rustc_data_structures::sso::SsoHashSet;
|
||||||
use smallvec::SmallVec;
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
|
||||||
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||||
|
use smallvec::{smallvec, SmallVec};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Component<'tcx> {
|
pub enum Component<'tcx> {
|
||||||
|
@ -47,14 +47,16 @@ pub enum Component<'tcx> {
|
||||||
EscapingProjection(Vec<Component<'tcx>>),
|
EscapingProjection(Vec<Component<'tcx>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TyCtxt<'tcx> {
|
/// Push onto `out` all the things that must outlive `'a` for the condition
|
||||||
/// Push onto `out` all the things that must outlive `'a` for the condition
|
/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
|
||||||
/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
|
pub fn push_outlives_components(
|
||||||
pub fn push_outlives_components(self, ty0: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>) {
|
tcx: TyCtxt<'tcx>,
|
||||||
let mut visited = SsoHashSet::new();
|
ty0: Ty<'tcx>,
|
||||||
compute_components(self, ty0, out, &mut visited);
|
out: &mut SmallVec<[Component<'tcx>; 4]>,
|
||||||
debug!("components({:?}) = {:?}", ty0, out);
|
) {
|
||||||
}
|
let mut visited = SsoHashSet::new();
|
||||||
|
compute_components(tcx, ty0, out, &mut visited);
|
||||||
|
debug!("components({:?}) = {:?}", ty0, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compute_components(
|
fn compute_components(
|
|
@ -1,5 +1,6 @@
|
||||||
//! Various code related to computing outlives relations.
|
//! Various code related to computing outlives relations.
|
||||||
|
|
||||||
|
pub mod components;
|
||||||
pub mod env;
|
pub mod env;
|
||||||
pub mod obligations;
|
pub mod obligations;
|
||||||
pub mod verify;
|
pub mod verify;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
//! Code that handles "type-outlives" constraints like `T: 'a`. This
|
//! Code that handles "type-outlives" constraints like `T: 'a`. This
|
||||||
//! is based on the `push_outlives_components` function defined on the tcx,
|
//! is based on the `push_outlives_components` function defined in rustc_infer,
|
||||||
//! but it adds a bit of heuristics on top, in particular to deal with
|
//! but it adds a bit of heuristics on top, in particular to deal with
|
||||||
//! associated types and projections.
|
//! associated types and projections.
|
||||||
//!
|
//!
|
||||||
|
@ -59,13 +59,13 @@
|
||||||
//! might later infer `?U` to something like `&'b u32`, which would
|
//! might later infer `?U` to something like `&'b u32`, which would
|
||||||
//! imply that `'b: 'a`.
|
//! imply that `'b: 'a`.
|
||||||
|
|
||||||
|
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||||
use crate::infer::outlives::env::RegionBoundPairs;
|
use crate::infer::outlives::env::RegionBoundPairs;
|
||||||
use crate::infer::outlives::verify::VerifyBoundCx;
|
use crate::infer::outlives::verify::VerifyBoundCx;
|
||||||
use crate::infer::{
|
use crate::infer::{
|
||||||
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
|
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
|
||||||
};
|
};
|
||||||
use crate::traits::{ObligationCause, ObligationCauseCode};
|
use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||||
use rustc_middle::ty::outlives::Component;
|
|
||||||
use rustc_middle::ty::subst::GenericArgKind;
|
use rustc_middle::ty::subst::GenericArgKind;
|
||||||
use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ where
|
||||||
assert!(!ty.has_escaping_bound_vars());
|
assert!(!ty.has_escaping_bound_vars());
|
||||||
|
|
||||||
let mut components = smallvec![];
|
let mut components = smallvec![];
|
||||||
self.tcx.push_outlives_components(ty, &mut components);
|
push_outlives_components(self.tcx, ty, &mut components);
|
||||||
self.components_must_outlive(origin, &components, region);
|
self.components_must_outlive(origin, &components, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use smallvec::smallvec;
|
use smallvec::smallvec;
|
||||||
|
|
||||||
|
use crate::infer::outlives::components::{push_outlives_components, Component};
|
||||||
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
|
||||||
use rustc_middle::ty::outlives::Component;
|
|
||||||
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
|
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ impl Elaborator<'tcx> {
|
||||||
|
|
||||||
let visited = &mut self.visited;
|
let visited = &mut self.visited;
|
||||||
let mut components = smallvec![];
|
let mut components = smallvec![];
|
||||||
tcx.push_outlives_components(ty_max, &mut components);
|
push_outlives_components(tcx, ty_max, &mut components);
|
||||||
self.stack.extend(
|
self.stack.extend(
|
||||||
components
|
components
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -92,7 +92,6 @@ pub mod fold;
|
||||||
pub mod inhabitedness;
|
pub mod inhabitedness;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
pub mod normalize_erasing_regions;
|
pub mod normalize_erasing_regions;
|
||||||
pub mod outlives;
|
|
||||||
pub mod print;
|
pub mod print;
|
||||||
pub mod query;
|
pub mod query;
|
||||||
pub mod relate;
|
pub mod relate;
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_infer::infer::canonical::{self, Canonical};
|
use rustc_infer::infer::canonical::{self, Canonical};
|
||||||
|
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
|
||||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||||
use rustc_infer::traits::TraitEngineExt as _;
|
use rustc_infer::traits::TraitEngineExt as _;
|
||||||
use rustc_middle::ty::outlives::Component;
|
|
||||||
use rustc_middle::ty::query::Providers;
|
use rustc_middle::ty::query::Providers;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||||
use rustc_span::source_map::DUMMY_SP;
|
use rustc_span::source_map::DUMMY_SP;
|
||||||
|
@ -118,7 +118,7 @@ fn compute_implied_outlives_bounds<'tcx>(
|
||||||
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
|
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
|
||||||
let ty_a = infcx.resolve_vars_if_possible(ty_a);
|
let ty_a = infcx.resolve_vars_if_possible(ty_a);
|
||||||
let mut components = smallvec![];
|
let mut components = smallvec![];
|
||||||
tcx.push_outlives_components(ty_a, &mut components);
|
push_outlives_components(tcx, ty_a, &mut components);
|
||||||
implied_bounds_from_components(r_b, components)
|
implied_bounds_from_components(r_b, components)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use rustc_middle::ty::outlives::Component;
|
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
|
||||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
|
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
|
||||||
use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
@ -35,7 +35,7 @@ pub fn insert_outlives_predicate<'tcx>(
|
||||||
// Or if within `struct Foo<U>` you had `T = Vec<U>`, then
|
// Or if within `struct Foo<U>` you had `T = Vec<U>`, then
|
||||||
// we would want to add `U: 'outlived_region`
|
// we would want to add `U: 'outlived_region`
|
||||||
let mut components = smallvec![];
|
let mut components = smallvec![];
|
||||||
tcx.push_outlives_components(ty, &mut components);
|
push_outlives_components(tcx, ty, &mut components);
|
||||||
for component in components {
|
for component in components {
|
||||||
match component {
|
match component {
|
||||||
Component::Region(r) => {
|
Component::Region(r) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue