1 use std::ops::ControlFlow;
3 use rustc_data_structures::intern::Interned;
5 use crate::ty::{FallibleTypeFolder, Ty, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor};
7 #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
8 pub struct ExternalConstraints<'tcx>(pub(crate) Interned<'tcx, ExternalConstraintsData<'tcx>>);
10 impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
11 type Target = ExternalConstraintsData<'tcx>;
13 fn deref(&self) -> &Self::Target {
18 /// Additional constraints returned on success.
19 #[derive(Debug, PartialEq, Eq, Clone, Hash, Default)]
20 pub struct ExternalConstraintsData<'tcx> {
21 // FIXME: implement this.
23 pub opaque_types: Vec<(Ty<'tcx>, Ty<'tcx>)>,
26 impl<'tcx> TypeFoldable<'tcx> for ExternalConstraints<'tcx> {
27 fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
28 Ok(FallibleTypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
33 .map(|opaque| opaque.try_fold_with(folder))
34 .collect::<Result<_, F::Error>>()?,
38 fn fold_with<F: TypeFolder<'tcx>>(self, folder: &mut F) -> Self {
39 TypeFolder::tcx(folder).intern_external_constraints(ExternalConstraintsData {
41 opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(),
46 impl<'tcx> TypeVisitable<'tcx> for ExternalConstraints<'tcx> {
47 fn visit_with<V: TypeVisitor<'tcx>>(
50 ) -> std::ops::ControlFlow<V::BreakTy> {
51 self.regions.visit_with(visitor)?;
52 self.opaque_types.visit_with(visitor)?;
53 ControlFlow::Continue(())