diff options
Diffstat (limited to 'crates/hir_ty/src/traits.rs')
-rw-r--r-- | crates/hir_ty/src/traits.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index dfa51896b..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)] |
42 | pub struct TraitEnvironment { | 42 | pub 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 | ||
46 | impl TraitEnvironment { | 49 | impl 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 | } |
@@ -129,7 +132,7 @@ pub(crate) fn trait_solve_query( | |||
129 | log::info!("trait_solve_query({})", goal.value.value.display(db)); | 132 | log::info!("trait_solve_query({})", goal.value.value.display(db)); |
130 | 133 | ||
131 | if let Obligation::Projection(pred) = &goal.value.value { | 134 | if let Obligation::Projection(pred) = &goal.value.value { |
132 | if let Ty::Bound(_) = &pred.projection_ty.parameters[0] { | 135 | if let Ty::BoundVar(_) = &pred.projection_ty.parameters[0] { |
133 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible | 136 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible |
134 | return Some(Solution::Ambig(Guidance::Unknown)); | 137 | return Some(Solution::Ambig(Guidance::Unknown)); |
135 | } | 138 | } |