aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/builder.rs2
-rw-r--r--crates/hir_ty/src/chalk_cast.rs20
-rw-r--r--crates/hir_ty/src/infer.rs1
-rw-r--r--crates/hir_ty/src/infer/coerce.rs4
-rw-r--r--crates/hir_ty/src/infer/expr.rs1
-rw-r--r--crates/hir_ty/src/infer/unify.rs2
-rw-r--r--crates/hir_ty/src/lib.rs3
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/hir_ty/src/method_resolution.rs10
-rw-r--r--crates/hir_ty/src/traits.rs12
-rw-r--r--crates/hir_ty/src/traits/chalk.rs2
-rw-r--r--crates/hir_ty/src/traits/chalk/mapping.rs7
-rw-r--r--crates/hir_ty/src/utils.rs14
-rw-r--r--crates/hir_ty/src/walk.rs9
14 files changed, 20 insertions, 69 deletions
diff --git a/crates/hir_ty/src/builder.rs b/crates/hir_ty/src/builder.rs
index 9a698898b..e25ef866d 100644
--- a/crates/hir_ty/src/builder.rs
+++ b/crates/hir_ty/src/builder.rs
@@ -14,7 +14,7 @@ use smallvec::SmallVec;
14use crate::{ 14use crate::{
15 db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders, 15 db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders,
16 CallableSig, FnPointer, FnSig, FnSubst, GenericArg, Interner, ProjectionTy, Substitution, 16 CallableSig, FnPointer, FnSig, FnSubst, GenericArg, Interner, ProjectionTy, Substitution,
17 TraitRef, Ty, TyDefId, TyExt, TyKind, TypeWalk, ValueTyDefId, 17 TraitRef, Ty, TyDefId, TyExt, TyKind, ValueTyDefId,
18}; 18};
19 19
20/// This is a builder for `Ty` or anything that needs a `Substitution`. 20/// This is a builder for `Ty` or anything that needs a `Substitution`.
diff --git a/crates/hir_ty/src/chalk_cast.rs b/crates/hir_ty/src/chalk_cast.rs
index 8bdd32ad6..f27dee3fd 100644
--- a/crates/hir_ty/src/chalk_cast.rs
+++ b/crates/hir_ty/src/chalk_cast.rs
@@ -1,14 +1,8 @@
1//! Implementations of the Chalk `Cast` trait for our types. 1//! Implementations of the Chalk `Cast` trait for our types.
2 2
3use chalk_ir::{ 3use chalk_ir::interner::HasInterner;
4 cast::{Cast, CastTo},
5 interner::HasInterner,
6};
7 4
8use crate::{ 5use crate::{CallableSig, ReturnTypeImplTraits};
9 AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig,
10 ReturnTypeImplTraits, TraitRef, Ty, WhereClause,
11};
12 6
13macro_rules! has_interner { 7macro_rules! has_interner {
14 ($t:ty) => { 8 ($t:ty) => {
@@ -18,15 +12,5 @@ macro_rules! has_interner {
18 }; 12 };
19} 13}
20 14
21macro_rules! transitive_impl {
22 ($a:ty, $b:ty, $c:ty) => {
23 impl CastTo<$c> for $a {
24 fn cast_to(self, interner: &Interner) -> $c {
25 self.cast::<$b>(interner).cast(interner)
26 }
27 }
28 };
29}
30
31has_interner!(CallableSig); 15has_interner!(CallableSig);
32has_interner!(ReturnTypeImplTraits); 16has_interner!(ReturnTypeImplTraits);
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index 1d8184ef5..bf2da2d4a 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -38,7 +38,6 @@ use syntax::SmolStr;
38 38
39use super::{ 39use super::{
40 DomainGoal, Guidance, InEnvironment, ProjectionTy, Solution, TraitEnvironment, TraitRef, Ty, 40 DomainGoal, Guidance, InEnvironment, ProjectionTy, Solution, TraitEnvironment, TraitRef, Ty,
41 TypeWalk,
42}; 41};
43use crate::{ 42use crate::{
44 db::HirDatabase, fold_tys, infer::diagnostics::InferenceDiagnostic, 43 db::HirDatabase, fold_tys, infer::diagnostics::InferenceDiagnostic,
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index 26dc6ceba..1f463a425 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -73,11 +73,11 @@ impl<'a> InferenceContext<'a> {
73 // Pointer weakening and function to pointer 73 // Pointer weakening and function to pointer
74 match (from_ty.kind(&Interner), to_ty.kind(&Interner)) { 74 match (from_ty.kind(&Interner), to_ty.kind(&Interner)) {
75 // `*mut T` -> `*const T` 75 // `*mut T` -> `*const T`
76 (TyKind::Raw(m1, inner), TyKind::Raw(m2 @ Mutability::Not, ..)) => { 76 (TyKind::Raw(_, inner), TyKind::Raw(m2 @ Mutability::Not, ..)) => {
77 from_ty = TyKind::Raw(*m2, inner.clone()).intern(&Interner); 77 from_ty = TyKind::Raw(*m2, inner.clone()).intern(&Interner);
78 } 78 }
79 // `&mut T` -> `&T` 79 // `&mut T` -> `&T`
80 (TyKind::Ref(m1, lt, inner), TyKind::Ref(m2 @ Mutability::Not, ..)) => { 80 (TyKind::Ref(_, lt, inner), TyKind::Ref(m2 @ Mutability::Not, ..)) => {
81 from_ty = TyKind::Ref(*m2, lt.clone(), inner.clone()).intern(&Interner); 81 from_ty = TyKind::Ref(*m2, lt.clone(), inner.clone()).intern(&Interner);
82 } 82 }
83 // `&T` -> `*const T` 83 // `&T` -> `*const T`
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 5f03079e8..cbbfa8b5c 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -24,7 +24,6 @@ use crate::{
24 utils::{generics, Generics}, 24 utils::{generics, Generics},
25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner, 25 AdtId, Binders, CallableDefId, FnPointer, FnSig, FnSubst, InEnvironment, Interner,
26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind, 26 ProjectionTyExt, Rawness, Scalar, Substitution, TraitRef, Ty, TyBuilder, TyExt, TyKind,
27 TypeWalk,
28}; 27};
29 28
30use super::{ 29use super::{
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 3b9c4a495..a887e20b0 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -12,7 +12,7 @@ use super::{DomainGoal, InferenceContext};
12use crate::{ 12use crate::{
13 fold_tys, static_lifetime, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, 13 fold_tys, static_lifetime, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds,
14 DebruijnIndex, FnPointer, FnSubst, InEnvironment, InferenceVar, Interner, Scalar, Substitution, 14 DebruijnIndex, FnPointer, FnSubst, InEnvironment, InferenceVar, Interner, Scalar, Substitution,
15 Ty, TyExt, TyKind, TypeWalk, WhereClause, 15 Ty, TyExt, TyKind, WhereClause,
16}; 16};
17 17
18impl<'a> InferenceContext<'a> { 18impl<'a> InferenceContext<'a> {
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index f7af8b8aa..874c95411 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -1,8 +1,6 @@
1//! The type system. We currently use this to infer types for completion, hover 1//! The type system. We currently use this to infer types for completion, hover
2//! information and various assists. 2//! information and various assists.
3 3
4#![allow(unused)]
5
6#[allow(unused)] 4#[allow(unused)]
7macro_rules! eprintln { 5macro_rules! eprintln {
8 ($($tt:tt)*) => { stdx::eprintln!($($tt)*) }; 6 ($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
@@ -34,7 +32,6 @@ use std::sync::Arc;
34 32
35use base_db::salsa; 33use base_db::salsa;
36use chalk_ir::{ 34use chalk_ir::{
37 cast::{CastTo, Caster},
38 fold::{Fold, Shift}, 35 fold::{Fold, Shift},
39 interner::HasInterner, 36 interner::HasInterner,
40 UintTy, 37 UintTy,
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 6584bcf34..8a22d9ea3 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -35,7 +35,7 @@ use crate::{
35 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig, 35 AliasEq, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, DynTy, FnPointer, FnSig,
36 FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause, 36 FnSubst, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionTy, QuantifiedWhereClause,
37 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution, 37 QuantifiedWhereClauses, ReturnTypeImplTrait, ReturnTypeImplTraits, Substitution,
38 TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, TypeWalk, WhereClause, 38 TraitEnvironment, TraitRef, TraitRefExt, Ty, TyBuilder, TyKind, WhereClause,
39}; 39};
40 40
41#[derive(Debug)] 41#[derive(Debug)]
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs
index 766880b14..be3e4f09a 100644
--- a/crates/hir_ty/src/method_resolution.rs
+++ b/crates/hir_ty/src/method_resolution.rs
@@ -6,11 +6,7 @@ use std::{iter, sync::Arc};
6 6
7use arrayvec::ArrayVec; 7use arrayvec::ArrayVec;
8use base_db::CrateId; 8use base_db::CrateId;
9use chalk_ir::{ 9use chalk_ir::{cast::Cast, Mutability, UniverseIndex};
10 cast::Cast,
11 fold::{Fold, Folder},
12 Fallible, Mutability, UniverseIndex,
13};
14use hir_def::{ 10use hir_def::{
15 lang_item::LangItemTarget, nameres::DefMap, AssocContainerId, AssocItemId, FunctionId, 11 lang_item::LangItemTarget, nameres::DefMap, AssocContainerId, AssocItemId, FunctionId,
16 GenericDefId, HasModule, ImplId, Lookup, ModuleId, TraitId, 12 GenericDefId, HasModule, ImplId, Lookup, ModuleId, TraitId,
@@ -25,9 +21,9 @@ use crate::{
25 primitive::{self, FloatTy, IntTy, UintTy}, 21 primitive::{self, FloatTy, IntTy, UintTy},
26 static_lifetime, 22 static_lifetime,
27 utils::all_super_traits, 23 utils::all_super_traits,
28 AdtId, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId, 24 AdtId, Canonical, CanonicalVarKinds, DebruijnIndex, FnPointer, FnSig, ForeignDefId,
29 InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder, 25 InEnvironment, Interner, Scalar, Substitution, TraitEnvironment, TraitRefExt, Ty, TyBuilder,
30 TyExt, TyKind, TypeWalk, 26 TyExt, TyKind,
31}; 27};
32 28
33/// This is used as a key for indexing impls. 29/// This is used as a key for indexing impls.
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs
index 63d87fe61..1cda72d22 100644
--- a/crates/hir_ty/src/traits.rs
+++ b/crates/hir_ty/src/traits.rs
@@ -12,7 +12,7 @@ use crate::{
12 Solution, TraitRefExt, Ty, TyKind, WhereClause, 12 Solution, TraitRefExt, Ty, TyKind, WhereClause,
13}; 13};
14 14
15use self::chalk::{from_chalk, Interner, ToChalk}; 15use self::chalk::Interner;
16 16
17pub(crate) mod chalk; 17pub(crate) mod chalk;
18 18
@@ -101,8 +101,7 @@ pub(crate) fn trait_solve_query(
101 // We currently don't deal with universes (I think / hope they're not yet 101 // We currently don't deal with universes (I think / hope they're not yet
102 // relevant for our use cases?) 102 // relevant for our use cases?)
103 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 }; 103 let u_canonical = chalk_ir::UCanonical { canonical, universes: 1 };
104 let solution = solve(db, krate, &u_canonical); 104 solve(db, krate, &u_canonical)
105 solution.map(|solution| solution_from_chalk(db, solution))
106} 105}
107 106
108fn solve( 107fn solve(
@@ -170,13 +169,6 @@ fn is_chalk_print() -> bool {
170 std::env::var("CHALK_PRINT").is_ok() 169 std::env::var("CHALK_PRINT").is_ok()
171} 170}
172 171
173fn solution_from_chalk(
174 db: &dyn HirDatabase,
175 solution: chalk_solve::Solution<Interner>,
176) -> Solution {
177 solution
178}
179
180#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] 172#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
181pub enum FnTrait { 173pub enum FnTrait {
182 FnOnce, 174 FnOnce,
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index e2a54fd92..b8c390b2e 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3 3
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds}; 6use chalk_ir::{fold::shift::Shift, CanonicalVarKinds};
7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; 7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
8 8
9use base_db::{salsa::InternKey, CrateId}; 9use base_db::{salsa::InternKey, CrateId};
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs
index 4abc0fbf2..7818f6387 100644
--- a/crates/hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/hir_ty/src/traits/chalk/mapping.rs
@@ -3,16 +3,15 @@
3//! Chalk (in both directions); plus some helper functions for more specialized 3//! Chalk (in both directions); plus some helper functions for more specialized
4//! conversions. 4//! conversions.
5 5
6use chalk_ir::{cast::Cast, interner::HasInterner}; 6use chalk_ir::cast::Cast;
7use chalk_solve::rust_ir; 7use chalk_solve::rust_ir;
8 8
9use base_db::salsa::InternKey; 9use base_db::salsa::InternKey;
10use hir_def::{GenericDefId, TypeAliasId}; 10use hir_def::{GenericDefId, TypeAliasId};
11 11
12use crate::{ 12use crate::{
13 db::HirDatabase, static_lifetime, AliasTy, CallableDefId, Canonical, ConstrainedSubst, 13 db::HirDatabase, AliasTy, CallableDefId, ProjectionTyExt, QuantifiedWhereClause, Substitution,
14 DomainGoal, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy, ProjectionTyExt, 14 Ty, WhereClause,
15 QuantifiedWhereClause, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
16}; 15};
17 16
18use super::interner::*; 17use super::interner::*;
diff --git a/crates/hir_ty/src/utils.rs b/crates/hir_ty/src/utils.rs
index d26f5152c..5f6cb052a 100644
--- a/crates/hir_ty/src/utils.rs
+++ b/crates/hir_ty/src/utils.rs
@@ -1,6 +1,5 @@
1//! Helper functions for working with def, which don't need to be a separate 1//! Helper functions for working with def, which don't need to be a separate
2//! query, but can't be computed directly from `*Data` (ie, which need a `db`). 2//! query, but can't be computed directly from `*Data` (ie, which need a `db`).
3use std::sync::Arc;
4 3
5use chalk_ir::{fold::Shift, BoundVar, DebruijnIndex}; 4use chalk_ir::{fold::Shift, BoundVar, DebruijnIndex};
6use hir_def::{ 5use hir_def::{
@@ -16,9 +15,7 @@ use hir_def::{
16}; 15};
17use hir_expand::name::{name, Name}; 16use hir_expand::name::{name, Name};
18 17
19use crate::{ 18use crate::{db::HirDatabase, Interner, Substitution, TraitRef, TraitRefExt, TyKind, WhereClause};
20 db::HirDatabase, Interner, Substitution, TraitRef, TraitRefExt, TyKind, TypeWalk, WhereClause,
21};
22 19
23fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> { 20fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
24 let resolver = trait_.resolver(db); 21 let resolver = trait_.resolver(db);
@@ -137,15 +134,6 @@ pub(super) fn associated_type_by_name_including_super_traits(
137 }) 134 })
138} 135}
139 136
140/// Helper for mutating `Arc<[T]>` (i.e. `Arc::make_mut` for Arc slices).
141/// The underlying values are cloned if there are other strong references.
142pub(crate) fn make_mut_slice<T: Clone>(a: &mut Arc<[T]>) -> &mut [T] {
143 if Arc::get_mut(a).is_none() {
144 *a = a.iter().cloned().collect();
145 }
146 Arc::get_mut(a).unwrap()
147}
148
149pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { 137pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics {
150 let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); 138 let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def)));
151 Generics { def, params: db.generic_params(def), parent_generics } 139 Generics { def, params: db.generic_params(def), parent_generics }
diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs
index 57343fd61..6ef1d5336 100644
--- a/crates/hir_ty/src/walk.rs
+++ b/crates/hir_ty/src/walk.rs
@@ -1,14 +1,11 @@
1//! The `TypeWalk` trait (probably to be replaced by Chalk's `Fold` and 1//! The `TypeWalk` trait (probably to be replaced by Chalk's `Fold` and
2//! `Visit`). 2//! `Visit`).
3 3
4use std::mem; 4use chalk_ir::interner::HasInterner;
5
6use chalk_ir::{interner::HasInterner, DebruijnIndex};
7 5
8use crate::{ 6use crate::{
9 utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, 7 AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, GenericArgData, Interner,
10 GenericArgData, Interner, OpaqueTy, ProjectionTy, Substitution, TraitRef, Ty, TyKind, 8 OpaqueTy, ProjectionTy, Substitution, TraitRef, Ty, TyKind, WhereClause,
11 WhereClause,
12}; 9};
13 10
14/// This allows walking structures that contain types to do something with those 11/// This allows walking structures that contain types to do something with those