|
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 |
|
| 8 | +pub trait RelateExt: InferCtxtLike { |
| 9 | + fn relate<T: Relate<Self::Interner>>( |
| 10 | + &self, |
| 11 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 12 | + lhs: T, |
| 13 | + variance: ty::Variance, |
| 14 | + rhs: T, |
| 15 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>; |
| 16 | + |
| 17 | + fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>( |
| 18 | + &self, |
| 19 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 20 | + lhs: T, |
| 21 | + rhs: T, |
| 22 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution>; |
| 23 | +} |
| 24 | + |
| 25 | +impl<Infcx: InferCtxtLike> RelateExt for Infcx { |
| 26 | + fn relate<T: Relate<Self::Interner>>( |
| 27 | + &self, |
| 28 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 29 | + lhs: T, |
| 30 | + variance: ty::Variance, |
| 31 | + rhs: T, |
| 32 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution> |
| 33 | + { |
| 34 | + let mut relate = |
| 35 | + SolverRelating::new(self, StructurallyRelateAliases::No, variance, param_env); |
| 36 | + relate.relate(lhs, rhs)?; |
| 37 | + Ok(relate.goals) |
| 38 | + } |
| 39 | + |
| 40 | + fn eq_structurally_relating_aliases<T: Relate<Self::Interner>>( |
| 41 | + &self, |
| 42 | + param_env: <Self::Interner as Interner>::ParamEnv, |
| 43 | + lhs: T, |
| 44 | + rhs: T, |
| 45 | + ) -> Result<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>, NoSolution> |
| 46 | + { |
| 47 | + let mut relate = |
| 48 | + SolverRelating::new(self, StructurallyRelateAliases::Yes, ty::Invariant, param_env); |
| 49 | + relate.relate(lhs, rhs)?; |
| 50 | + Ok(relate.goals) |
| 51 | + } |
| 52 | +} |
| 53 | + |
8 | 54 | #[allow(unused)]
|
9 | 55 | /// Enforce that `a` is equal to or a subtype of `b`.
|
10 | 56 | pub struct SolverRelating<'infcx, Infcx, I: Interner> {
|
|
20 | 66 | Infcx: InferCtxtLike<Interner = I>,
|
21 | 67 | I: Interner,
|
22 | 68 | {
|
| 69 | + fn new( |
| 70 | + infcx: &'infcx Infcx, |
| 71 | + structurally_relate_aliases: StructurallyRelateAliases, |
| 72 | + ambient_variance: ty::Variance, |
| 73 | + param_env: I::ParamEnv, |
| 74 | + ) -> Self { |
| 75 | + SolverRelating { |
| 76 | + infcx, |
| 77 | + structurally_relate_aliases, |
| 78 | + ambient_variance, |
| 79 | + param_env, |
| 80 | + goals: vec![], |
| 81 | + } |
| 82 | + } |
23 | 83 | }
|
24 | 84 |
|
25 | 85 | impl<Infcx, I> TypeRelation<I> for SolverRelating<'_, Infcx, I>
|
|
0 commit comments