Skip to content

Commit 57b15d4

Browse files
committed
fix FromEnv transformation for higher-ranked clauses
If we have `where for<'a> T: Foo<'a>`, that should generate `for<'a> FromEnv(T: Foo<'a>)` in the environment.
1 parent 2b3a37f commit 57b15d4

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

chalk-ir/src/lib.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,20 +1145,28 @@ pub enum ProgramClause<I: Interner> {
11451145
ForAll(Binders<ProgramClauseImplication<I>>),
11461146
}
11471147

1148+
impl<I: Interner> ProgramClauseImplication<I> {
1149+
pub fn into_from_env_clause(self, interner: &I) -> ProgramClauseImplication<I> {
1150+
if self.conditions.is_empty(interner) {
1151+
ProgramClauseImplication {
1152+
consequence: self.consequence.into_from_env_goal(interner),
1153+
conditions: self.conditions.clone(),
1154+
}
1155+
} else {
1156+
self
1157+
}
1158+
}
1159+
}
1160+
11481161
impl<I: Interner> ProgramClause<I> {
11491162
pub fn into_from_env_clause(self, interner: &I) -> ProgramClause<I> {
11501163
match self {
11511164
ProgramClause::Implies(implication) => {
1152-
if implication.conditions.is_empty(interner) {
1153-
ProgramClause::Implies(ProgramClauseImplication {
1154-
consequence: implication.consequence.into_from_env_goal(interner),
1155-
conditions: Goals::new(interner),
1156-
})
1157-
} else {
1158-
ProgramClause::Implies(implication)
1159-
}
1165+
ProgramClause::Implies(implication.into_from_env_clause(interner))
1166+
}
1167+
ProgramClause::ForAll(binders_implication) => {
1168+
ProgramClause::ForAll(binders_implication.map(|i| i.into_from_env_clause(interner)))
11601169
}
1161-
clause => clause,
11621170
}
11631171
}
11641172
}

0 commit comments

Comments
 (0)