Skip to content

Commit e561538

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

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

chalk-solve/src/clauses.rs

+11
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,16 @@ fn program_clauses_that_could_match(
167168
}
168169
}
169170

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

0 commit comments

Comments
 (0)