aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/traits.rs
diff options
context:
space:
mode:
authorSeivan Heidari <[email protected]>2019-11-18 01:27:53 +0000
committerSeivan Heidari <[email protected]>2019-11-18 01:27:53 +0000
commit166636ba77adcf5bf2c4ef935e9aa75e20f25e10 (patch)
tree168be1ca55c73b016e20586c08417c608450c92c /crates/ra_hir/src/ty/traits.rs
parentcb26df950699586b314731fb70786e0db8eaa049 (diff)
parent28c2d74b2150102a8756a5357a5a965d7610bd15 (diff)
Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into feature/themes
Diffstat (limited to 'crates/ra_hir/src/ty/traits.rs')
-rw-r--r--crates/ra_hir/src/ty/traits.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs
index 4f1eab150..45f725438 100644
--- a/crates/ra_hir/src/ty/traits.rs
+++ b/crates/ra_hir/src/ty/traits.rs
@@ -8,7 +8,7 @@ use ra_prof::profile;
8use rustc_hash::FxHashSet; 8use rustc_hash::FxHashSet;
9 9
10use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; 10use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk};
11use crate::{db::HirDatabase, expr::ExprId, Crate, DefWithBody, ImplBlock, Trait}; 11use crate::{db::HirDatabase, expr::ExprId, Crate, DefWithBody, ImplBlock, Trait, TypeAlias};
12 12
13use self::chalk::{from_chalk, ToChalk}; 13use self::chalk::{from_chalk, ToChalk};
14 14
@@ -17,7 +17,7 @@ pub(crate) mod chalk;
17#[derive(Debug, Clone)] 17#[derive(Debug, Clone)]
18pub struct TraitSolver { 18pub struct TraitSolver {
19 krate: Crate, 19 krate: Crate,
20 inner: Arc<Mutex<chalk_solve::Solver>>, 20 inner: Arc<Mutex<chalk_solve::Solver<ChalkIr>>>,
21} 21}
22 22
23/// We need eq for salsa 23/// We need eq for salsa
@@ -34,7 +34,7 @@ impl TraitSolver {
34 &self, 34 &self,
35 db: &impl HirDatabase, 35 db: &impl HirDatabase,
36 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<ChalkIr>>>, 36 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<ChalkIr>>>,
37 ) -> Option<chalk_solve::Solution> { 37 ) -> Option<chalk_solve::Solution<ChalkIr>> {
38 let context = ChalkContext { db, krate: self.krate }; 38 let context = ChalkContext { db, krate: self.krate };
39 debug!("solve goal: {:?}", goal); 39 debug!("solve goal: {:?}", goal);
40 let mut solver = match self.inner.lock() { 40 let mut solver = match self.inner.lock() {
@@ -165,9 +165,9 @@ impl TypeWalk for ProjectionPredicate {
165 self.ty.walk(f); 165 self.ty.walk(f);
166 } 166 }
167 167
168 fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 168 fn walk_mut_binders(&mut self, f: &mut impl FnMut(&mut Ty, usize), binders: usize) {
169 self.projection_ty.walk_mut(f); 169 self.projection_ty.walk_mut_binders(f, binders);
170 self.ty.walk_mut(f); 170 self.ty.walk_mut_binders(f, binders);
171 } 171 }
172} 172}
173 173
@@ -188,6 +188,7 @@ pub(crate) fn trait_solve_query(
188 } 188 }
189 189
190 let canonical = goal.to_chalk(db).cast(); 190 let canonical = goal.to_chalk(db).cast();
191
191 // We currently don't deal with universes (I think / hope they're not yet 192 // We currently don't deal with universes (I think / hope they're not yet
192 // relevant for our use cases?) 193 // relevant for our use cases?)
193 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 }; 194 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 };
@@ -195,7 +196,10 @@ pub(crate) fn trait_solve_query(
195 solution.map(|solution| solution_from_chalk(db, solution)) 196 solution.map(|solution| solution_from_chalk(db, solution))
196} 197}
197 198
198fn solution_from_chalk(db: &impl HirDatabase, solution: chalk_solve::Solution) -> Solution { 199fn solution_from_chalk(
200 db: &impl HirDatabase,
201 solution: chalk_solve::Solution<ChalkIr>,
202) -> Solution {
199 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<ChalkIr>>| { 203 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<ChalkIr>>| {
200 let value = subst 204 let value = subst
201 .value 205 .value
@@ -300,3 +304,14 @@ pub enum Impl {
300 /// Closure types implement the Fn traits synthetically. 304 /// Closure types implement the Fn traits synthetically.
301 ClosureFnTraitImpl(ClosureFnTraitImplData), 305 ClosureFnTraitImpl(ClosureFnTraitImplData),
302} 306}
307
308/// An associated type value. Usually this comes from a `type` declaration
309/// inside an impl block, but for built-in impls we have to synthesize it.
310/// (We only need this because Chalk wants a unique ID for each of these.)
311#[derive(Debug, Clone, PartialEq, Eq, Hash)]
312pub enum AssocTyValue {
313 /// A normal assoc type value from an impl block.
314 TypeAlias(TypeAlias),
315 /// The output type of the Fn trait implementation.
316 ClosureFnTraitImplOutput(ClosureFnTraitImplData),
317}