|
1 | 1 | pub use rustc_type_ir::relate::*;
|
2 |
| -use rustc_type_ir::solve::Goal; |
| 2 | +use rustc_type_ir::solve::{Goal, NoSolution}; |
3 | 3 | use rustc_type_ir::{self as ty, InferCtxtLike, Interner};
|
4 | 4 | use tracing::{debug, instrument};
|
5 | 5 |
|
6 | 6 | use self::combine::{InferCtxtCombineExt, PredicateEmittingRelation};
|
7 | 7 | use crate::data_structures::DelayedSet;
|
8 | 8 |
|
| 9 | +pub trait RelateExt: InferCtxtLike { |
| 10 | + fn relate<T: Relate<Self::Interner>>( |
| 11 | + &self, |
| 12 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 13 | + lhs: T, |
| 14 | + variance: ty::Variance, |
| 15 | + rhs: T, |
| 16 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>; |
| 17 | + |
| 18 | + fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>( |
| 19 | + &self, |
| 20 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 21 | + lhs: T, |
| 22 | + rhs: T, |
| 23 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>; |
| 24 | +} |
| 25 | + |
| 26 | +impl<Infcx: InferCtxtLike> RelateExt for Infcx { |
| 27 | + fn relate<T: Relate<Self::Interner>>( |
| 28 | + &self, |
| 29 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 30 | + lhs: T, |
| 31 | + variance: ty::Variance, |
| 32 | + rhs: T, |
| 33 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution> |
| 34 | + { |
| 35 | + let mut relate = |
| 36 | + SolverRelating::new(self, StructurallyRelateAliases::No, variance, param_env); |
| 37 | + relate.relate(lhs, rhs)?; |
| 38 | + Ok(relate.goals) |
| 39 | + } |
| 40 | + |
| 41 | + fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>( |
| 42 | + &self, |
| 43 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 44 | + lhs: T, |
| 45 | + rhs: T, |
| 46 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution> |
| 47 | + { |
| 48 | + let mut relate = |
| 49 | + SolverRelating::new(self, StructurallyRelateAliases::Yes, ty::Invariant, param_env); |
| 50 | + relate.relate(lhs, rhs)?; |
| 51 | + Ok(relate.goals) |
| 52 | + } |
| 53 | +} |
| 54 | + |
9 | 55 | #[allow(unused)]
|
10 | 56 | /// Enforce that `a` is equal to or a subtype of `b`.
|
11 | 57 | pub struct SolverRelating<'infcx, Infcx, I: Interner> {
|
|
46 | 92 | Infcx: InferCtxtLike<Interner = I>,
|
47 | 93 | I: Interner,
|
48 | 94 | {
|
| 95 | + fn new( |
| 96 | + infcx: &'infcx Infcx, |
| 97 | + structurally_relate_aliases: StructurallyRelateAliases, |
| 98 | + ambient_variance: ty::Variance, |
| 99 | + param_env: I::ParamEnv, |
| 100 | + ) -> Self { |
| 101 | + SolverRelating { |
| 102 | + infcx, |
| 103 | + structurally_relate_aliases, |
| 104 | + ambient_variance, |
| 105 | + param_env, |
| 106 | + goals: vec![], |
| 107 | + cache: Default::default(), |
| 108 | + } |
| 109 | + } |
49 | 110 | }
|
50 | 111 |
|
51 | 112 | impl<Infcx, I> TypeRelation<I> for SolverRelating<'_, Infcx, I>
|
|
0 commit comments