1 use crate::infer::InferCtxt;
3 use rustc_middle::ty::error::TypeError;
4 use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
5 use rustc_middle::ty::{self, Ty, TyCtxt};
7 pub struct CollectAllMismatches<'a, 'tcx> {
8 pub infcx: &'a InferCtxt<'tcx>,
9 pub param_env: ty::ParamEnv<'tcx>,
10 pub errors: Vec<TypeError<'tcx>>,
13 impl<'a, 'tcx> TypeRelation<'tcx> for CollectAllMismatches<'a, 'tcx> {
14 fn tag(&self) -> &'static str {
15 "CollectAllMismatches"
17 fn tcx(&self) -> TyCtxt<'tcx> {
20 fn intercrate(&self) -> bool {
23 fn param_env(&self) -> ty::ParamEnv<'tcx> {
26 fn a_is_expected(&self) -> bool {
29 fn mark_ambiguous(&mut self) {
32 fn relate_with_variance<T: Relate<'tcx>>(
35 _: ty::VarianceDiagInfo<'tcx>,
38 ) -> RelateResult<'tcx, T> {
45 ) -> RelateResult<'tcx, ty::Region<'tcx>> {
48 fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
49 if a == b || matches!(a.kind(), ty::Infer(_)) || matches!(b.kind(), ty::Infer(_)) {
52 relate::super_relate_tys(self, a, b).or_else(|e| {
61 ) -> RelateResult<'tcx, ty::Const<'tcx>> {
65 relate::super_relate_consts(self, a, b) // could do something similar here for constants!
67 fn binders<T: Relate<'tcx>>(
69 a: ty::Binder<'tcx, T>,
70 b: ty::Binder<'tcx, T>,
71 ) -> RelateResult<'tcx, ty::Binder<'tcx, T>> {
72 Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))