aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/traits.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-23 10:58:06 +0000
committerGitHub <[email protected]>2019-12-23 10:58:06 +0000
commitce07a2daa9e53aa86a769f8641b14c2878444fbc (patch)
treefc5802a209c642e862171a1d022634eefd2a03a9 /crates/ra_hir_ty/src/traits.rs
parent31c5888a4c0913c44d13f25f8cb79e0701e84f71 (diff)
parent1f7f4578f72721c1b0e17e8405f986fd2ce89aaf (diff)
Merge #2636
2636: Chalk update and refactoring r=flodiebold a=flodiebold This updates the Chalk integration to https://github.com/rust-lang/chalk/pull/311, which will presumably get merged soon, and refactors it some more, most notably introducing our own `TypeFamily` instead of reusing `ChalkIr`. It's still mostly the same as `ChalkIr` though, except for using Salsa `InternId`s directly. Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_hir_ty/src/traits.rs')
-rw-r--r--crates/ra_hir_ty/src/traits.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs
index d49f8fb4b..c4dc857bc 100644
--- a/crates/ra_hir_ty/src/traits.rs
+++ b/crates/ra_hir_ty/src/traits.rs
@@ -1,7 +1,7 @@
1//! Trait solving using Chalk. 1//! Trait solving using Chalk.
2use std::sync::{Arc, Mutex}; 2use std::sync::{Arc, Mutex};
3 3
4use chalk_ir::{cast::Cast, family::ChalkIr}; 4use chalk_ir::cast::Cast;
5use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId}; 5use hir_def::{expr::ExprId, DefWithBodyId, ImplId, TraitId, TypeAliasId};
6use log::debug; 6use log::debug;
7use ra_db::{impl_intern_key, salsa, CrateId}; 7use ra_db::{impl_intern_key, salsa, CrateId};
@@ -12,7 +12,7 @@ use crate::db::HirDatabase;
12 12
13use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk}; 13use super::{Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TypeWalk};
14 14
15use self::chalk::{from_chalk, ToChalk}; 15use self::chalk::{from_chalk, ToChalk, TypeFamily};
16 16
17pub(crate) mod chalk; 17pub(crate) mod chalk;
18mod builtin; 18mod builtin;
@@ -20,7 +20,7 @@ mod builtin;
20#[derive(Debug, Clone)] 20#[derive(Debug, Clone)]
21pub struct TraitSolver { 21pub struct TraitSolver {
22 krate: CrateId, 22 krate: CrateId,
23 inner: Arc<Mutex<chalk_solve::Solver<ChalkIr>>>, 23 inner: Arc<Mutex<chalk_solve::Solver<TypeFamily>>>,
24} 24}
25 25
26/// We need eq for salsa 26/// We need eq for salsa
@@ -36,8 +36,8 @@ impl TraitSolver {
36 fn solve( 36 fn solve(
37 &self, 37 &self,
38 db: &impl HirDatabase, 38 db: &impl HirDatabase,
39 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<ChalkIr>>>, 39 goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<TypeFamily>>>,
40 ) -> Option<chalk_solve::Solution<ChalkIr>> { 40 ) -> Option<chalk_solve::Solution<TypeFamily>> {
41 let context = ChalkContext { db, krate: self.krate }; 41 let context = ChalkContext { db, krate: self.krate };
42 debug!("solve goal: {:?}", goal); 42 debug!("solve goal: {:?}", goal);
43 let mut solver = match self.inner.lock() { 43 let mut solver = match self.inner.lock() {
@@ -201,17 +201,17 @@ pub(crate) fn trait_solve_query(
201 201
202fn solution_from_chalk( 202fn solution_from_chalk(
203 db: &impl HirDatabase, 203 db: &impl HirDatabase,
204 solution: chalk_solve::Solution<ChalkIr>, 204 solution: chalk_solve::Solution<TypeFamily>,
205) -> Solution { 205) -> Solution {
206 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<ChalkIr>>| { 206 let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| {
207 let value = subst 207 let value = subst
208 .value 208 .value
209 .parameters 209 .parameters
210 .into_iter() 210 .into_iter()
211 .map(|p| { 211 .map(|p| {
212 let ty = match p { 212 let ty = match p.ty() {
213 chalk_ir::Parameter(chalk_ir::ParameterKind::Ty(ty)) => from_chalk(db, ty), 213 Some(ty) => from_chalk(db, ty.clone()),
214 chalk_ir::Parameter(chalk_ir::ParameterKind::Lifetime(_)) => unimplemented!(), 214 None => unimplemented!(),
215 }; 215 };
216 ty 216 ty
217 }) 217 })
@@ -291,7 +291,7 @@ impl FnTrait {
291 } 291 }
292} 292}
293 293
294#[derive(Debug, Clone, PartialEq, Eq, Hash)] 294#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
295pub struct ClosureFnTraitImplData { 295pub struct ClosureFnTraitImplData {
296 def: DefWithBodyId, 296 def: DefWithBodyId,
297 expr: ExprId, 297 expr: ExprId,
@@ -300,7 +300,7 @@ pub struct ClosureFnTraitImplData {
300 300
301/// An impl. Usually this comes from an impl block, but some built-in types get 301/// An impl. Usually this comes from an impl block, but some built-in types get
302/// synthetic impls. 302/// synthetic impls.
303#[derive(Debug, Clone, PartialEq, Eq, Hash)] 303#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
304pub enum Impl { 304pub enum Impl {
305 /// A normal impl from an impl block. 305 /// A normal impl from an impl block.
306 ImplBlock(ImplId), 306 ImplBlock(ImplId),