diff options
author | Florian Diebold <[email protected]> | 2021-03-18 20:53:19 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2021-03-18 20:53:19 +0000 |
commit | 7a7e47eab7323a8e122d9994b2936e50e42a1af2 (patch) | |
tree | a2ad2b6faf8c708fc593546df64d489c117b61f2 /crates/hir_ty/src/infer | |
parent | b70bea0d7994cbe7b1e01e6b2e0f4ab3ac2c6fd5 (diff) |
Chalkify TraitRef
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 13 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 12 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 4 |
4 files changed, 22 insertions, 13 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index b1f98c507..b86474ed4 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -8,7 +8,8 @@ use chalk_ir::{Mutability, TyVariableKind}; | |||
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | autoderef, traits::Solution, Interner, Obligation, Substitution, TraitRef, Ty, TyKind, | 11 | autoderef, to_chalk_trait_id, traits::Solution, Interner, Obligation, Substitution, TraitRef, |
12 | Ty, TyKind, | ||
12 | }; | 13 | }; |
13 | 14 | ||
14 | use super::{InEnvironment, InferenceContext}; | 15 | use super::{InEnvironment, InferenceContext}; |
@@ -140,7 +141,8 @@ impl<'a> InferenceContext<'a> { | |||
140 | .push(from_ty.clone()) | 141 | .push(from_ty.clone()) |
141 | .push(to_ty.clone()) | 142 | .push(to_ty.clone()) |
142 | .build(); | 143 | .build(); |
143 | let trait_ref = TraitRef { trait_: coerce_unsized_trait, substs }; | 144 | let trait_ref = |
145 | TraitRef { trait_id: to_chalk_trait_id(coerce_unsized_trait), substitution: substs }; | ||
144 | let goal = InEnvironment::new(self.trait_env.clone(), Obligation::Trait(trait_ref)); | 146 | let goal = InEnvironment::new(self.trait_env.clone(), Obligation::Trait(trait_ref)); |
145 | 147 | ||
146 | let canonicalizer = self.canonicalizer(); | 148 | let canonicalizer = self.canonicalizer(); |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 0be8c5a90..93548b6c0 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -18,7 +18,7 @@ use crate::{ | |||
18 | lower::lower_to_chalk_mutability, | 18 | lower::lower_to_chalk_mutability, |
19 | method_resolution, op, | 19 | method_resolution, op, |
20 | primitive::{self, UintTy}, | 20 | primitive::{self, UintTy}, |
21 | to_assoc_type_id, | 21 | to_assoc_type_id, to_chalk_trait_id, |
22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, | 22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, |
23 | utils::{generics, variant_data, Generics}, | 23 | utils::{generics, variant_data, Generics}, |
24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, | 24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, |
@@ -90,8 +90,10 @@ impl<'a> InferenceContext<'a> { | |||
90 | Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); | 90 | Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); |
91 | 91 | ||
92 | let trait_env = Arc::clone(&self.trait_env); | 92 | let trait_env = Arc::clone(&self.trait_env); |
93 | let implements_fn_trait = | 93 | let implements_fn_trait = Obligation::Trait(TraitRef { |
94 | Obligation::Trait(TraitRef { trait_: fn_once_trait, substs: substs.clone() }); | 94 | trait_id: to_chalk_trait_id(fn_once_trait), |
95 | substitution: substs.clone(), | ||
96 | }); | ||
95 | let goal = self.canonicalizer().canonicalize_obligation(InEnvironment { | 97 | let goal = self.canonicalizer().canonicalize_obligation(InEnvironment { |
96 | value: implements_fn_trait.clone(), | 98 | value: implements_fn_trait.clone(), |
97 | environment: trait_env, | 99 | environment: trait_env, |
@@ -948,7 +950,10 @@ impl<'a> InferenceContext<'a> { | |||
948 | // construct a TraitDef | 950 | // construct a TraitDef |
949 | let substs = | 951 | let substs = |
950 | parameters.prefix(generics(self.db.upcast(), trait_.into()).len()); | 952 | parameters.prefix(generics(self.db.upcast(), trait_.into()).len()); |
951 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); | 953 | self.obligations.push(Obligation::Trait(TraitRef { |
954 | trait_id: to_chalk_trait_id(trait_), | ||
955 | substitution: substs, | ||
956 | })); | ||
952 | } | 957 | } |
953 | } | 958 | } |
954 | CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {} | 959 | CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {} |
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index ea01d6238..e15135fc1 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs | |||
@@ -9,7 +9,9 @@ use hir_def::{ | |||
9 | }; | 9 | }; |
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
12 | use crate::{method_resolution, Interner, Substitution, Ty, TyKind, ValueTyDefId}; | 12 | use crate::{ |
13 | method_resolution, to_chalk_trait_id, Interner, Substitution, Ty, TyKind, ValueTyDefId, | ||
14 | }; | ||
13 | 15 | ||
14 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 16 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
15 | 17 | ||
@@ -165,7 +167,7 @@ impl<'a> InferenceContext<'a> { | |||
165 | segment: PathSegment<'_>, | 167 | segment: PathSegment<'_>, |
166 | id: ExprOrPatId, | 168 | id: ExprOrPatId, |
167 | ) -> Option<(ValueNs, Option<Substitution>)> { | 169 | ) -> Option<(ValueNs, Option<Substitution>)> { |
168 | let trait_ = trait_ref.trait_; | 170 | let trait_ = trait_ref.hir_trait_id(); |
169 | let item = | 171 | let item = |
170 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { | 172 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { |
171 | match item { | 173 | match item { |
@@ -200,7 +202,7 @@ impl<'a> InferenceContext<'a> { | |||
200 | }; | 202 | }; |
201 | 203 | ||
202 | self.write_assoc_resolution(id, item); | 204 | self.write_assoc_resolution(id, item); |
203 | Some((def, Some(trait_ref.substs))) | 205 | Some((def, Some(trait_ref.substitution))) |
204 | } | 206 | } |
205 | 207 | ||
206 | fn resolve_ty_assoc_item( | 208 | fn resolve_ty_assoc_item( |
@@ -255,8 +257,8 @@ impl<'a> InferenceContext<'a> { | |||
255 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) | 257 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) |
256 | .build(); | 258 | .build(); |
257 | self.obligations.push(super::Obligation::Trait(TraitRef { | 259 | self.obligations.push(super::Obligation::Trait(TraitRef { |
258 | trait_, | 260 | trait_id: to_chalk_trait_id(trait_), |
259 | substs: trait_substs.clone(), | 261 | substitution: trait_substs.clone(), |
260 | })); | 262 | })); |
261 | Some(trait_substs) | 263 | Some(trait_substs) |
262 | } | 264 | } |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index b2d4f67b3..f5ea09698 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -390,9 +390,9 @@ impl InferenceTable { | |||
390 | ) -> bool { | 390 | ) -> bool { |
391 | match (pred1, pred2) { | 391 | match (pred1, pred2) { |
392 | (GenericPredicate::Implemented(tr1), GenericPredicate::Implemented(tr2)) | 392 | (GenericPredicate::Implemented(tr1), GenericPredicate::Implemented(tr2)) |
393 | if tr1.trait_ == tr2.trait_ => | 393 | if tr1.trait_id == tr2.trait_id => |
394 | { | 394 | { |
395 | self.unify_substs(&tr1.substs, &tr2.substs, depth + 1) | 395 | self.unify_substs(&tr1.substitution, &tr2.substitution, depth + 1) |
396 | } | 396 | } |
397 | (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2)) | 397 | (GenericPredicate::Projection(proj1), GenericPredicate::Projection(proj2)) |
398 | if proj1.projection_ty.associated_ty_id == proj2.projection_ty.associated_ty_id => | 398 | if proj1.projection_ty.associated_ty_id == proj2.projection_ty.associated_ty_id => |