use alloc::borrow::ToOwned;
use alloc::boxed::Box;
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use core::fmt;
use core::ops::Index;
use crate::rustc_index::{IndexSlice, IndexVec};
use crate::rustc_middle::mir::ConstraintCategory;
use crate::rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo};
use crate::rustc_span::Span;
use tracing::debug;
use crate::rustc_borrowck::type_check::Locations;
pub(crate) mod graph;
#[derive(Clone, Debug, Default)]
pub(crate) struct OutlivesConstraintSet<'tcx> {
outlives: IndexVec<OutlivesConstraintIndex, OutlivesConstraint<'tcx>>,
}
impl<'tcx> OutlivesConstraintSet<'tcx> {
pub(crate) fn push(&mut self, constraint: OutlivesConstraint<'tcx>) {
debug!("OutlivesConstraintSet::push({:?})", constraint);
if constraint.sup == constraint.sub {
return;
}
self.outlives.push(constraint);
}
pub(crate) fn graph(&self, num_region_vars: usize) -> graph::NormalConstraintGraph {
graph::ConstraintGraph::new(graph::Normal, self, num_region_vars)
}
pub(crate) fn reverse_graph(&self, num_region_vars: usize) -> graph::ReverseConstraintGraph {
graph::ConstraintGraph::new(graph::Reverse, self, num_region_vars)
}
pub(crate) fn outlives(
&self,
) -> &IndexSlice<OutlivesConstraintIndex, OutlivesConstraint<'tcx>> {
&self.outlives
}
}
impl<'tcx> Index<OutlivesConstraintIndex> for OutlivesConstraintSet<'tcx> {
type Output = OutlivesConstraint<'tcx>;
fn index(&self, i: OutlivesConstraintIndex) -> &Self::Output {
&self.outlives[i]
}
}
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct OutlivesConstraint<'tcx> {
pub sup: RegionVid,
pub sub: RegionVid,
pub locations: Locations,
pub span: Span,
pub category: ConstraintCategory<'tcx>,
pub variance_info: VarianceDiagInfo<TyCtxt<'tcx>>,
pub from_closure: bool,
}
impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
formatter,
"({:?}: {:?}) due to {:?} ({:?}) ({:?}) (span: {:?})",
self.sup, self.sub, self.locations, self.variance_info, self.category, self.span,
)
}
}
crate::rustc_index::newtype_index! {
#[debug_format = "OutlivesConstraintIndex({})"]
pub(crate) struct OutlivesConstraintIndex {}
}
crate::rustc_index::newtype_index! {
#[orderable]
#[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex {}
}