Skip to content

Commit 8e2bdaa

Browse files
committed
Add wf_clause_for_fn_def
1 parent 26e0ea8 commit 8e2bdaa

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/librustc_traits/chalk_context/program_clauses.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,24 @@ fn wf_clause_for_ref<'tcx>(
343343
tcx.mk_clauses(iter::once(wf_clause))
344344
}
345345

346+
fn wf_clause_for_fn_def<'tcx>(
347+
tcx: ty::TyCtxt<'_, '_, 'tcx>,
348+
def_id: DefId
349+
) -> Clauses<'tcx> {
350+
let fn_def = generic_types::fn_def(tcx, def_id);
351+
352+
let wf_clause = ProgramClause {
353+
goal: DomainGoal::WellFormed(WellFormed::Ty(fn_def)),
354+
hypotheses: ty::List::empty(),
355+
category: ProgramClauseCategory::WellFormed,
356+
};
357+
let wf_clause = Clause::ForAll(ty::Binder::bind(wf_clause));
358+
359+
// `forall <T1, ..., Tn+1> { WellFormed(fn some_fn(T1, ..., Tn) -> Tn+1). }`
360+
// where `def_id` maps to the `some_fn` function definition
361+
tcx.mk_clauses(iter::once(wf_clause))
362+
}
363+
346364
impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
347365
pub(super) fn program_clauses_impl(
348366
&self,
@@ -506,6 +524,8 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
506524
// WF if `sub_ty` outlives `region`.
507525
ty::Ref(_, _, mutbl) => wf_clause_for_ref(self.infcx.tcx, mutbl),
508526

527+
ty::FnDef(def_id, ..) => wf_clause_for_fn_def(self.infcx.tcx, def_id),
528+
509529
ty::Dynamic(..) => {
510530
// FIXME: no rules yet for trait objects
511531
ty::List::empty()
@@ -515,8 +535,8 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
515535
self.infcx.tcx.program_clauses_for(def.did)
516536
}
517537

538+
// FIXME: these are probably wrong
518539
ty::Foreign(def_id) |
519-
ty::FnDef(def_id, ..) |
520540
ty::Closure(def_id, ..) |
521541
ty::Generator(def_id, ..) |
522542
ty::Opaque(def_id, ..) => {

0 commit comments

Comments
 (0)