predicates_for_object_candidate in rustc_next_trait_solver::solve::assembly::structural_traits - Rust
Description: Assemble a list of predicates that would be present on a theoretical user impl for an object type. These predicates must be checked any time we assemble a built-in object candidate for an object type, since they are not implied by the well-formedness of the type.

Skip to main content

## predicates_for_object_candidate

# Function predicates_for_object_candidate

Source

    pub(in solve) fn predicates_for_object_candidate<D, I>(
        ecx: &mut EvalCtxt<'_, D>,
        param_env: I::ParamEnv,
        trait_ref: Binder<I, TraitRef<I>>,
        object_bounds: I::BoundExistentialPredicates,
    ) -> Result<Vec<Goal<I, I::Predicate>>, Ambiguous>where
        D: SolverDelegate<Interner = I>,
        I: Interner,

Expand description

Assemble a list of predicates that would be present on a theoretical user impl for an object type. These predicates must be checked any time we assemble a built-in object candidate for an object type, since they are not implied by the well-formedness of the type.

For example, given the following traits:

ⓘ

    trait Foo: Baz {
        type Bar: Copy;
    }

    trait Baz {}

For the dyn type `dyn Foo<Item = Ty>`, we can imagine there being a pair of theoretical impls:

ⓘ

    impl Foo for dyn Foo<Item = Ty>
    where
        Self: Baz,
        <Self as Foo>::Bar: Copy,
    {
        type Bar = Ty;
    }

    impl Baz for dyn Foo<Item = Ty> {}

However, in order to make such impls non-cyclical, we need to do an additional step of eagerly folding the associated types in the where clauses of the impl. In this example, that means replacing `<Self as Foo>::Bar` with `Ty` in the first impl.