fn add_user_pred<'c>(&self, user_computed_preds: &mut FxHashSet<ty::Predicate<'c>>,
                         new_pred: ty::Predicate<'c>) {
        let mut should_add_new = true;
        user_computed_preds.retain(|&old_pred| {
            match (&new_pred, old_pred) {
                (&ty::Predicate::Trait(new_trait), ty::Predicate::Trait(old_trait)) => {
                    if new_trait.def_id() == old_trait.def_id() {
                        let new_substs = new_trait.skip_binder().trait_ref.substs;
                        let old_substs = old_trait.skip_binder().trait_ref.substs;
                        if !new_substs.types().eq(old_substs.types()) {
                            // We can't compare lifetimes if the types are different,
                            // so skip checking old_pred
                            return true
                        }

                        for (new_region, old_region) in new_substs
                            .regions()
                            .zip(old_substs.regions()) {

                            match (new_region, old_region) {
                                // If both predicates have an 'ReLateBound' (a HRTB) in the
                                // same spot, we do nothing
                                (
                                    ty::RegionKind::ReLateBound(_, _),
                                    ty::RegionKind::ReLateBound(_, _)
                                ) => {},

                                (ty::RegionKind::ReLateBound(_, _), _) => {
                                    // The new predicate has a HRTB in a spot where the old
                                    // predicate does not (if they both had a HRTB, the previous
                                    // match arm would have executed).
                                    //
                                    // The means we want to remove the older predicate from
                                    // user_computed_preds, since having both it and the new
                                    // predicate in a ParamEnv would confuse SelectionContext
                                    // We're currently in the predicate passed to 'retain',
                                    // so we return 'false' to remove the old predicate from
                                    // user_computed_preds
                                    return false;
                                },
                                (_, ty::RegionKind::ReLateBound(_, _)) => {
                                    // This is the opposite situation as the previous arm - the
                                    // old predicate has a HRTB lifetime in a place where the
                                    // new predicate does not. We want to leave the old
                                    // predicate in user_computed_preds, and skip adding
                                    // new_pred to user_computed_params.
                                    should_add_new = false
                                }
                                _ => {}
                            }
                        }
                    }
                },
                _ => {}
            }
            return true
        });

        if should_add_new {
            user_computed_preds.insert(new_pred);
        }
    }
// This method is designed to work around the following issue:
// When we compute auto trait bounds, we repeatedly call SelectionContext.select,
// progressively building a ParamEnv based on the results we get.
// However, our usage of SelectionContext differs from its normal use within the compiler,
// in that we capture and re-reprocess predicates from Unimplemented errors.
//
// This can lead to a corner case when dealing with region parameters.
// During our selection loop in evaluate_predicates, we might end up with
// two trait predicates that differ only in their region parameters:
// one containing a HRTB lifetime parameter, and one containing a 'normal'
// lifetime parameter. For example:
//
// T as MyTrait<'a>
// T as MyTrait<'static>
//
// If we put both of these predicates in our computed ParamEnv, we'll
// confuse SelectionContext, since it will (correctly) view both as being applicable.
//
// To solve this, we pick the 'more strict' lifetime bound - i.e. the HRTB
// Our end goal is to generate a user-visible description of the conditions
// under which a type implements an auto trait. A trait predicate involving
// a HRTB means that the type needs to work with any choice of lifetime,
// not just one specific lifetime (e.g. 'static).
This method is designed to work around the following issue:
When we compute auto trait bounds, we repeatedly call SelectionContext.select,
progressively building a ParamEnv based on the results we get.
However, our usage of SelectionContext differs from its normal use within the compiler,
in that we capture and re-reprocess predicates from Unimplemented errors.

This can lead to a corner case when dealing with region parameters.
During our selection loop in evaluate_predicates, we might end up with
two trait predicates that differ only in their region parameters:
one containing a HRTB lifetime parameter, and one containing a 'normal'
lifetime parameter. For example.



If we put both of these predicates in our computed ParamEnv, we'll
confuse SelectionContext, since it will (correctly) view both as being applicable.

To solve this, we pick the 'more strict' lifetime bound - i.e. the HRTB
Our end goal is to generate a user-visible description of the conditions
under which a type implements an auto trait. A trait predicate involving
a HRTB means that the type needs to work with any choice of lifetime,
not just one specific lifetime .
This method is designed to work around the following issue : When we compute auto trait bounds we repeatedly call SelectionContext . select progressively building a ParamEnv based on the results we get . However our usage of SelectionContext differs from its normal use within the compiler in that we capture and re - reprocess predicates from Unimplemented errors . This can lead to a corner case when dealing with region parameters . During our selection loop in evaluate_predicates we might end up with two trait predicates that differ only in their region parameters : one containing a HRTB lifetime parameter and one containing a ' normal ' lifetime parameter . For example . If we put both of these predicates in our computed ParamEnv we ' ll confuse SelectionContext since it will ( correctly ) view both as being applicable . To solve this we pick the ' more strict ' lifetime bound - i . e . the HRTB Our end goal is to generate a user - visible description of the conditions under which a type implements an auto trait . A trait predicate involving a HRTB means that the type needs to work with any choice of lifetime not just one specific lifetime .
fn add_user_pred<'c>(&self, user_computed_preds: &mut FxHashSet<ty::Predicate<'c>>,
                         new_pred: ty::Predicate<'c>) {
        let mut should_add_new = true;
        user_computed_preds.retain(|&old_pred| {
            match (&new_pred, old_pred) {
                (&ty::Predicate::Trait(new_trait), ty::Predicate::Trait(old_trait)) => {
                    if new_trait.def_id() == old_trait.def_id() {
                        let new_substs = new_trait.skip_binder().trait_ref.substs;
                        let old_substs = old_trait.skip_binder().trait_ref.substs;
                        if !new_substs.types().eq(old_substs.types()) {
                            // We can't compare lifetimes if the types are different,
                            // so skip checking old_pred
                            return true
                        }
                        for (new_region, old_region) in new_substs
                            .regions()
                            .zip(old_substs.regions()) {
                            match (new_region, old_region) {
                                // If both predicates have an 'ReLateBound' (a HRTB) in the
                                // same spot, we do nothing
                                (
                                    ty::RegionKind::ReLateBound(_, _),
                                    ty::RegionKind::ReLateBound(_, _)
                                ) => {},
                                (ty::RegionKind::ReLateBound(_, _), _) => {
                                    // The new predicate has a HRTB in a spot where the old
                                    // predicate does not (if they both had a HRTB, the previous
                                    // match arm would have executed).
                                    //
                                    // The means we want to remove the older predicate from
                                    // user_computed_preds, since having both it and the new
                                    // predicate in a ParamEnv would confuse SelectionContext
                                    // We're currently in the predicate passed to 'retain',
                                    // so we return 'false' to remove the old predicate from
                                    // user_computed_preds
                                    return false;
                                },
                                (_, ty::RegionKind::ReLateBound(_, _)) => {
                                    // This is the opposite situation as the previous arm - the
                                    // old predicate has a HRTB lifetime in a place where the
                                    // new predicate does not. We want to leave the old
                                    // predicate in user_computed_preds, and skip adding
                                    // new_pred to user_computed_params.
                                    should_add_new = false
                                }
                                _ => {}
                            }
                        }
                    }
                },
                _ => {}
            }
            return true
        });
        if should_add_new {
            user_computed_preds.insert(new_pred);
        }
    }
fn add_user_pred < ' c > ( & self , user_computed_preds : & mut FxHashSet < ty :: Predicate < ' c > > , new_pred : ty :: Predicate < ' c > ) { let mut should_add_new = true ; user_computed_preds . retain ( | & old_pred | { match ( & new_pred , old_pred ) { ( & ty :: Predicate :: Trait ( new_trait ) , ty :: Predicate :: Trait ( old_trait ) ) => { if new_trait . def_id ( ) == old_trait . def_id ( ) { let new_substs = new_trait . skip_binder ( ) . trait_ref . substs ; let old_substs = old_trait . skip_binder ( ) . trait_ref . substs ; if ! new_substs . types ( ) . eq ( old_substs . types ( ) ) { // We can't compare lifetimes if the types are different, // so skip checking old_pred return true } for ( new_region , old_region ) in new_substs . regions ( ) . zip ( old_substs . regions ( ) ) { match ( new_region , old_region ) { // If both predicates have an 'ReLateBound' (a HRTB) in the // same spot, we do nothing ( ty :: RegionKind :: ReLateBound ( _ , _ ) , ty :: RegionKind :: ReLateBound ( _ , _ ) ) => { } , ( ty :: RegionKind :: ReLateBound ( _ , _ ) , _ ) => { // The new predicate has a HRTB in a spot where the old // predicate does not (if they both had a HRTB, the previous // match arm would have executed). // // The means we want to remove the older predicate from // user_computed_preds, since having both it and the new // predicate in a ParamEnv would confuse SelectionContext // We're currently in the predicate passed to 'retain', // so we return 'false' to remove the old predicate from // user_computed_preds return false ; } , ( _ , ty :: RegionKind :: ReLateBound ( _ , _ ) ) => { // This is the opposite situation as the previous arm - the // old predicate has a HRTB lifetime in a place where the // new predicate does not. We want to leave the old // predicate in user_computed_preds, and skip adding // new_pred to user_computed_params. should_add_new = false } _ => { } } } } } , _ => { } } return true } ) ; if should_add_new { user_computed_preds . insert ( new_pred ) ; } }
This method is designed to work around the following issue:
When we compute auto trait bounds, we repeatedly call SelectionContext.select,
progressively building a ParamEnv based on the results we get.
This method is designed to work around the following issue : When we compute auto trait bounds we repeatedly call SelectionContext . select progressively building a ParamEnv based on the results we get .
&self
user_computed_preds
&mut FxHashSet<ty::Predicate<'c>>
new_pred
ty::Predicate<'c>
&self
user_computed_preds
&mut FxHashSet<ty::Predicate<'c>>
new_pred
ty::Predicate<'c>