2023-02-03 02:29:52 +00:00
|
|
|
use std::ops::ControlFlow;
|
|
|
|
|
|
|
|
use rustc_data_structures::intern::Interned;
|
|
|
|
|
2023-02-20 12:37:28 +01:00
|
|
|
use crate::infer::canonical::QueryRegionConstraints;
|
2023-02-09 14:02:47 +00:00
|
|
|
use crate::ty::{
|
2023-02-22 02:18:40 +00:00
|
|
|
FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
|
2023-02-09 14:02:47 +00:00
|
|
|
};
|
2023-02-03 02:29:52 +00:00
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
|
|
|
|
pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
|
|
|
|
|
|
|
|
impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
|
|
|
|
type Target = ExternalConstraintsData<'tcx>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&*self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Additional constraints returned on success.
|
2023-02-20 12:37:28 +01:00
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default, TypeFoldable, TypeVisitable)]
|
2023-02-03 02:29:52 +00:00
|
|
|
pub struct ExternalConstraintsData<'tcx> {
|
|
|
|
// FIXME: implement this.
|
2023-02-20 12:37:28 +01:00
|
|
|
pub region_constraints: QueryRegionConstraints<'tcx>,
|
2023-02-03 02:29:52 +00:00
|
|
|
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
|
|
|
|
}
|
|
|
|
|
2023-02-20 12:37:28 +01:00
|
|
|
// FIXME: Having to clone `region_constraints` for folding feels bad and
|
|
|
|
// probably isn't great wrt performance.
|
|
|
|
//
|
|
|
|
// Not sure how to fix this, maybe we should also intern `opaque_types` and
|
|
|
|
// `region_constraints` here or something.
|
2023-02-11 09:13:27 +00:00
|
|
|
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
|
2023-02-22 02:18:40 +00:00
|
|
|
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
|
|
|
|
self,
|
|
|
|
folder: &mut F,
|
|
|
|
) -> Result<Self, F::Error> {
|
2023-02-17 14:33:08 +11:00
|
|
|
Ok(FallibleTypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData {
|
2023-02-20 12:37:28 +01:00
|
|
|
region_constraints: self.region_constraints.clone().try_fold_with(folder)?,
|
2023-02-17 14:33:08 +11:00
|
|
|
opaque_types: self
|
|
|
|
.opaque_types
|
|
|
|
.iter()
|
|
|
|
.map(|opaque| opaque.try_fold_with(folder))
|
|
|
|
.collect::<Result<_, F::Error>>()?,
|
|
|
|
}))
|
2023-02-03 02:29:52 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 02:18:40 +00:00
|
|
|
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
|
2023-02-17 14:33:08 +11:00
|
|
|
TypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData {
|
2023-02-20 12:37:28 +01:00
|
|
|
region_constraints: self.region_constraints.clone().fold_with(folder),
|
2023-02-03 02:29:52 +00:00
|
|
|
opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-09 19:38:07 +00:00
|
|
|
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ExternalConstraints<'tcx> {
|
2023-02-22 02:18:40 +00:00
|
|
|
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(
|
2023-02-03 02:29:52 +00:00
|
|
|
&self,
|
|
|
|
visitor: &mut V,
|
|
|
|
) -> std::ops::ControlFlow<V::BreakTy> {
|
2023-02-20 12:37:28 +01:00
|
|
|
self.region_constraints.visit_with(visitor)?;
|
2023-02-03 02:29:52 +00:00
|
|
|
self.opaque_types.visit_with(visitor)?;
|
|
|
|
ControlFlow::Continue(())
|
|
|
|
}
|
|
|
|
}
|