fn predicate_can_apply<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                                 pred: ty::PolyTraitRef<'tcx>)
                                 -> bool
{
    struct ParamToVarFolder<'a, 'tcx: 'a> {
        infcx: &'a InferCtxt<'a, 'tcx>,
        var_map: FnvHashMap<Ty<'tcx>, Ty<'tcx>>
    }

    impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx>
    {
        fn tcx(&self) -> &TyCtxt<'tcx> { self.infcx.tcx }

        fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
            if let ty::TyParam(..) = ty.sty {
                let infcx = self.infcx;
                self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var())
            } else {
                ty.super_fold_with(self)
            }
        }
    }

    infcx.probe(|_| {
        let mut selcx = SelectionContext::new(infcx);

        let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
            infcx: infcx,
            var_map: FnvHashMap()
        });

        let cleaned_pred = super::project::normalize(
            &mut selcx,
            ObligationCause::dummy(),
            &cleaned_pred
        ).value;

        let obligation = Obligation::new(
            ObligationCause::dummy(),
            cleaned_pred.to_predicate()
        );

        selcx.evaluate_obligation(&obligation)
    })
}
/// Returns whether the trait predicate may apply for *some* assignment
/// to the type parameters.
Returns whether the trait predicate may apply for *some* assignment
to the type parameters.
Returns whether the trait predicate may apply for * some * assignment to the type parameters .
fn predicate_can_apply<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
                                 pred: ty::PolyTraitRef<'tcx>)
                                 -> bool
{
    struct ParamToVarFolder<'a, 'tcx: 'a> {
        infcx: &'a InferCtxt<'a, 'tcx>,
        var_map: FnvHashMap<Ty<'tcx>, Ty<'tcx>>
    }
    impl<'a, 'tcx> TypeFolder<'tcx> for ParamToVarFolder<'a, 'tcx>
    {
        fn tcx(&self) -> &TyCtxt<'tcx> { self.infcx.tcx }
        fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
            if let ty::TyParam(..) = ty.sty {
                let infcx = self.infcx;
                self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var())
            } else {
                ty.super_fold_with(self)
            }
        }
    }
    infcx.probe(|_| {
        let mut selcx = SelectionContext::new(infcx);
        let cleaned_pred = pred.fold_with(&mut ParamToVarFolder {
            infcx: infcx,
            var_map: FnvHashMap()
        });
        let cleaned_pred = super::project::normalize(
            &mut selcx,
            ObligationCause::dummy(),
            &cleaned_pred
        ).value;
        let obligation = Obligation::new(
            ObligationCause::dummy(),
            cleaned_pred.to_predicate()
        );
        selcx.evaluate_obligation(&obligation)
    })
}
fn predicate_can_apply < ' a , ' tcx > ( infcx : & InferCtxt < ' a , ' tcx > , pred : ty :: PolyTraitRef < ' tcx > ) -> bool { struct ParamToVarFolder < ' a , ' tcx : ' a > { infcx : & ' a InferCtxt < ' a , ' tcx > , var_map : FnvHashMap < Ty < ' tcx > , Ty < ' tcx > > } impl < ' a , ' tcx > TypeFolder < ' tcx > for ParamToVarFolder < ' a , ' tcx > { fn tcx ( & self ) -> & TyCtxt < ' tcx > { self . infcx . tcx } fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > { if let ty :: TyParam ( .. ) = ty . sty { let infcx = self . infcx ; self . var_map . entry ( ty ) . or_insert_with ( | | infcx . next_ty_var ( ) ) } else { ty . super_fold_with ( self ) } } } infcx . probe ( | _ | { let mut selcx = SelectionContext :: new ( infcx ) ; let cleaned_pred = pred . fold_with ( & mut ParamToVarFolder { infcx : infcx , var_map : FnvHashMap ( ) } ) ; let cleaned_pred = super :: project :: normalize ( & mut selcx , ObligationCause :: dummy ( ) , & cleaned_pred ) . value ; let obligation = Obligation :: new ( ObligationCause :: dummy ( ) , cleaned_pred . to_predicate ( ) ) ; selcx . evaluate_obligation ( & obligation ) } ) }
Returns whether the trait predicate may apply for *some* assignment
to the type parameters.
Returns whether the trait predicate may apply for * some * assignment to the type parameters .
infcx
&InferCtxt<'a, 'tcx>
pred
ty::PolyTraitRef<'tcx>
infcx
&InferCtxt<'a, 'tcx>
pred
ty::PolyTraitRef<'tcx>