Repository: rust-lang/rust
File: compiler/rustc_hir_analysis/src/check/wfcheck.rs (Rust)

Code before:
                ObligationCauseCode::WhereClause(def_id.to_def_id(), sp),
            );
            Obligation::new(tcx, cause, wfcx.param_env, pred)
        });

    let predicates = predicates.instantiate_identity(tcx);

    let assoc_const_obligations: Vec<_> = predicates
        .predicates
        .iter()
        .copied()
        .zip(predicates.spans.iter().copied())
        .filter_map(|(clause, sp)| clause.as_projection_clause().map(|proj| (proj, sp)))
        .filter_map(|(proj, sp)| {
            let pred_binder = proj
                .map_bound(|pred| {
                    pred.term.as_const().map(|ct| {
                        let assoc_const_ty = tcx
                            .type_of(pred.projection_term.def_id)
                            .instantiate(tcx, pred.projection_term.args);
                        ty::ClauseKind::ConstArgHasType(ct, assoc_const_ty)
                    })
                })
                .transpose();
            pred_binder.map(|pred_binder| {
                let pred: ty::Predicate<'tcx> = pred_binder.upcast(tcx);
                let cause = traits::ObligationCause::new(
                    sp,
                    wfcx.body_def_id,
                    ObligationCauseCode::WhereClause(def_id.to_def_id(), sp),
                );
                Obligation::new(tcx, cause, wfcx.param_env, pred)
            })
        })
        .collect();

    assert_eq!(predicates.predicates.len(), predicates.spans.len());
    let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
        traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp)
    });
    let obligations: Vec<_> =
        wf_obligations.chain(default_obligations).chain(assoc_const_obligations).collect();
    wfcx.register_obligations(obligations);
}

#[instrument(level = "debug", skip(wfcx, hir_decl))]
fn check_fn_or_method<'tcx>(
    wfcx: &WfCheckingCtxt<'_, 'tcx>,
    sig: ty::PolyFnSig<'tcx>,
    hir_decl: &hir::FnDecl<'_>,
    def_id: LocalDefId,

Review comment (suggestion):
`Obligation::new` accepts arbitrary `T` that implements `Upcast` you *might* be able to just do `Obligation::new(... pred_binder)` but I don't know for sure :)

Code after:
                ObligationCauseCode::WhereClause(def_id.to_def_id(), sp),
            );
            Obligation::new(tcx, cause, wfcx.param_env, pred)
        });

    let predicates = predicates.instantiate_identity(tcx);

    let assoc_const_obligations: Vec<_> = predicates
        .predicates
        .iter()
        .copied()
        .zip(predicates.spans.iter().copied())
        .filter_map(|(clause, sp)| {
            let proj = clause.as_projection_clause()?;
            let pred_binder = proj
                .map_bound(|pred| {
                    pred.term.as_const().map(|ct| {
                        let assoc_const_ty = tcx
                            .type_of(pred.projection_term.def_id)
                            .instantiate(tcx, pred.projection_term.args);
                        ty::ClauseKind::ConstArgHasType(ct, assoc_const_ty)
                    })
                })
                .transpose();
            pred_binder.map(|pred_binder| {
                let cause = traits::ObligationCause::new(
                    sp,
                    wfcx.body_def_id,
                    ObligationCauseCode::WhereClause(def_id.to_def_id(), sp),
                );
                Obligation::new(tcx, cause, wfcx.param_env, pred_binder)
            })
        })
        .collect();

    assert_eq!(predicates.predicates.len(), predicates.spans.len());
    let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| {
        traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp)
    });
    let obligations: Vec<_> =
        wf_obligations.chain(default_obligations).chain(assoc_const_obligations).collect();
    wfcx.register_obligations(obligations);
}

#[instrument(level = "debug", skip(wfcx, hir_decl))]
fn check_fn_or_method<'tcx>(
    wfcx: &WfCheckingCtxt<'_, 'tcx>,
    sig: ty::PolyFnSig<'tcx>,
    hir_decl: &hir::FnDecl<'_>,
    def_id: LocalDefId,
) {