Skip to content

Commit 454ff2c

Browse files
committed
Extend clauses.rs to support impl/dyn Trait
1 parent 36ddb8a commit 454ff2c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

chalk-solve/src/clauses.rs

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use self::program_clauses::ToProgramClauses;
33
use crate::RustIrDatabase;
44
use chalk_ir::cast::{Cast, Caster};
55
use chalk_ir::could_match::CouldMatch;
6+
use chalk_ir::fold::Subst;
67
use chalk_ir::*;
78
use rustc_hash::FxHashSet;
89
use std::sync::Arc;
@@ -167,6 +168,17 @@ fn program_clauses_that_could_match(
167168
}
168169
}
169170

171+
// Check for impl and dyn Traits so that we generate
172+
// `Implemented(impl Foo + Bar) :- Implemented(Foo), Implemented(Bar)`
173+
match trait_ref.self_type_parameter() {
174+
Some(Ty::Opaque(qwc)) | Some(Ty::Dyn(qwc)) => {
175+
let self_ty = trait_ref.self_type_parameter().unwrap(); // This cannot be None
176+
let wc = Subst::apply(&[self_ty.cast()], &qwc.value);
177+
clauses.extend(wc.into_iter().casted());
178+
}
179+
_ => {}
180+
}
181+
170182
// TODO sized, unsize_trait, builtin impls?
171183
}
172184
DomainGoal::Holds(WhereClause::ProjectionEq(projection_predicate)) => {

0 commit comments

Comments
 (0)