aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/traits.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-12 19:41:23 +0000
committerGitHub <[email protected]>2021-03-12 19:41:23 +0000
commit05814e542fe6a303aa2a0d23411391d904d1fa26 (patch)
treeeba9f9c4fe5c807b3ac27f0bc9d841f693843226 /crates/hir_ty/src/traits.rs
parentc0459c53572f90fa9134192e432562af3daba5fa (diff)
parentec70387a4cac131f34847c94e9fe7de66acc241e (diff)
Merge #7985
7985: Use Chalk Environment more directly r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/traits.rs')
-rw-r--r--crates/hir_ty/src/traits.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index e4cdb6d53..27f350f70 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -38,22 +38,25 @@ fn create_chalk_solver() -> chalk_recursive::RecursiveSolver<Interner> {
38/// fn foo<T: Default>(t: T) {} 38/// fn foo<T: Default>(t: T) {}
39/// ``` 39/// ```
40/// we assume that `T: Default`. 40/// we assume that `T: Default`.
41#[derive(Clone, Debug, PartialEq, Eq, Hash)] 41#[derive(Debug, Clone, PartialEq, Eq, Hash)]
42pub struct TraitEnvironment { 42pub struct TraitEnvironment {
43 pub predicates: Vec<GenericPredicate>, 43 // When we're using Chalk's Ty we can make this a BTreeMap since it's Ord,
44 // but for now it's too annoying...
45 pub(crate) traits_from_clauses: Vec<(Ty, TraitId)>,
46 pub(crate) env: chalk_ir::Environment<Interner>,
44} 47}
45 48
46impl TraitEnvironment { 49impl TraitEnvironment {
47 /// Returns trait refs with the given self type which are supposed to hold 50 pub(crate) fn traits_in_scope_from_clauses<'a>(
48 /// in this trait env. E.g. if we are in `foo<T: SomeTrait>()`, this will
49 /// find that `T: SomeTrait` if we call it for `T`.
50 pub(crate) fn trait_predicates_for_self_ty<'a>(
51 &'a self, 51 &'a self,
52 ty: &'a Ty, 52 ty: &'a Ty,
53 ) -> impl Iterator<Item = &'a TraitRef> + 'a { 53 ) -> impl Iterator<Item = TraitId> + 'a {
54 self.predicates.iter().filter_map(move |pred| match pred { 54 self.traits_from_clauses.iter().filter_map(move |(self_ty, trait_id)| {
55 GenericPredicate::Implemented(tr) if tr.self_ty() == ty => Some(tr), 55 if self_ty == ty {
56 _ => None, 56 Some(*trait_id)
57 } else {
58 None
59 }
57 }) 60 })
58 } 61 }
59} 62}