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"
18 fn tcx(&self) -> TyCtxt<'tcx> {
22 fn intercrate(&self) -> bool {
26 fn param_env(&self) -> ty::ParamEnv<'tcx> {
30 fn a_is_expected(&self) -> bool {
34 fn mark_ambiguous(&mut self) {
38 fn relate_with_variance<T: Relate<'tcx>>(
41 _: ty::VarianceDiagInfo<'tcx>,
44 ) -> RelateResult<'tcx, T> {
52 ) -> RelateResult<'tcx, ty::Region<'tcx>> {
56 fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
57 self.infcx.probe(|_| {
58 if a.is_ty_infer() || b.is_ty_infer() {
61 self.infcx.super_combine_tys(self, a, b).or_else(|e| {
73 ) -> RelateResult<'tcx, ty::Const<'tcx>> {
77 relate::super_relate_consts(self, a, b) // could do something similar here for constants!
80 fn binders<T: Relate<'tcx>>(
82 a: ty::Binder<'tcx, T>,
83 b: ty::Binder<'tcx, T>,
84 ) -> RelateResult<'tcx, ty::Binder<'tcx, T>> {
85 Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))