2023-02-03 02:29:52 +00:00
|
|
|
use std::ops::ControlFlow;
|
|
|
|
|
|
|
|
use rustc_data_structures::intern::Interned;
|
|
|
|
|
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.
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
|
|
|
|
pub struct ExternalConstraintsData<'tcx> {
|
|
|
|
// FIXME: implement this.
|
|
|
|
pub regions: (),
|
|
|
|
pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
|
|
|
|
}
|
|
|
|
|
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> {
|
|
|
|
Ok(FallibleTypeFolder::interner(folder).intern_external_constraints(
|
2023-02-09 14:02:47 +00:00
|
|
|
ExternalConstraintsData {
|
|
|
|
regions: (),
|
|
|
|
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 {
|
|
|
|
TypeFolder::interner(folder).intern_external_constraints(ExternalConstraintsData {
|
2023-02-03 02:29:52 +00:00
|
|
|
regions: (),
|
|
|
|
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> {
|
|
|
|
self.regions.visit_with(visitor)?;
|
|
|
|
self.opaque_types.visit_with(visitor)?;
|
|
|
|
ControlFlow::Continue(())
|
|
|
|
}
|
|
|
|
}
|