Unsatisfied trait bound for an associated type


I encountered an error around generic bounds for which I don't understand the reason.
I have a function with a generic parameter CR. Additionally it is bound by usize: CR::Arg:

fn synthesis_inner<P, CR> (
    inner: &ZkSyncUniformCircuitInstance<F, impl ZkSyncUniformSynthesisFunction<F>>,
    hint: &FinalizationHintsForProver,
) -> CSReferenceAssembly<F, P, ProvingCSConfig> where 
    P: PrimeFieldLikeVectorized<Base = F>,
    CR: CircuitResolver<F, <ProvingCSConfig as CSConfig>::ResolverConfig>,
    usize: Into<<CR as CircuitResolver<F, <ProvingCSConfig as CSConfig>::ResolverConfig>>::Arg>
    // function body

This raises an error:

the trait bound `CR: CircuitResolver<F, Resolver<DontPerformRuntimeAsserts>>` is not satisfied
    the trait `CircuitResolver<F, Resolver<DontPerformRuntimeAsserts>>` is not implemented for `CR` [E0277]

The solution was to modify the CR bound:

CR: CircuitResolver<F, Resolver<DontPerformRuntimeAsserts>>,

I'm puzzled as to why this worked, given that ProvingCSConfig is defined as

pub struct ProvingCSConfig;

impl CSConfig for ProvingCSConfig {
    type WitnessConfig = DoEvaluateWitenss;
    type DebugConfig = DontPerformRuntimeAsserts;
    type SetupConfig = DontKeepSetup;
    type ResolverConfig = Resolver<DontPerformRuntimeAsserts>;

Both the initial and the fixed version should be logically equivalent.

The compiler isn't perfect at performing this kind of reasoning — take a look through the issue tracker and you'll find many bugs of this flavor about “normalizing projections” — a “projection” is <Ty as Trait>::AssocTy, and “normalizing” is processing each of the involved types so that it can later tell they're equal. I don't know if there's one already filed for exactly your case.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.