Skip to content

Commit ec90c38

Browse files
committed
Add Deref definition clause on lowering.
The clause should be: forall<T, U> { Deref(T, U) :- ProjectionEq(<T as Deref>::Target = U>) }
1 parent 8286a02 commit ec90c38

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lower/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,31 @@ impl ir::Program {
10391039
);
10401040
program_clauses.extend(self.default_impl_data.iter().map(|d| d.to_program_clause()));
10411041

1042+
// Adds clause that defines Deref:
1043+
// forall<T, U> { Deref(T, U) :- ProjectionEq(<T as Deref>::Target = U>) }
1044+
if let Some(trait_id) = self.lang_items.get(&ir::LangItem::DerefTrait) {
1045+
// Find `Deref::Target`.
1046+
let associated_ty_id = self.associated_ty_data.values()
1047+
.find(|d| d.trait_id == *trait_id)
1048+
.expect("Deref has no assoc item")
1049+
.id;
1050+
let t = || ir::Ty::Var(0);
1051+
let u = || ir::Ty::Var(1);
1052+
program_clauses.push(ir::Binders {
1053+
binders: vec![ir::ParameterKind::Ty(()), ir::ParameterKind::Ty(())],
1054+
value: ir::ProgramClauseImplication {
1055+
consequence: ir::DomainGoal::Deref(ir::Deref { source: t(), target: u() }),
1056+
conditions: vec![ir::ProjectionEq {
1057+
projection: ir::ProjectionTy {
1058+
associated_ty_id,
1059+
parameters: vec![t().cast()]
1060+
},
1061+
ty: u(),
1062+
}.cast()]
1063+
},
1064+
}.cast());
1065+
}
1066+
10421067
for datum in self.impl_data.values() {
10431068
// If we encounter a negative impl, do not generate any rule. Negative impls
10441069
// are currently just there to deactivate default impls for auto traits.

0 commit comments

Comments
 (0)