aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r--crates/hir_ty/src/infer/coerce.rs7
-rw-r--r--crates/hir_ty/src/infer/expr.rs25
-rw-r--r--crates/hir_ty/src/infer/path.rs12
-rw-r--r--crates/hir_ty/src/infer/unify.rs13
4 files changed, 27 insertions, 30 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index b86474ed4..07eb96573 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -4,12 +4,11 @@
4//! 4//!
5//! See: https://doc.rust-lang.org/nomicon/coercions.html 5//! See: https://doc.rust-lang.org/nomicon/coercions.html
6 6
7use chalk_ir::{Mutability, TyVariableKind}; 7use chalk_ir::{cast::Cast, Mutability, TyVariableKind};
8use hir_def::lang_item::LangItemTarget; 8use hir_def::lang_item::LangItemTarget;
9 9
10use crate::{ 10use crate::{
11 autoderef, to_chalk_trait_id, traits::Solution, Interner, Obligation, Substitution, TraitRef, 11 autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty, TyKind,
12 Ty, TyKind,
13}; 12};
14 13
15use super::{InEnvironment, InferenceContext}; 14use super::{InEnvironment, InferenceContext};
@@ -143,7 +142,7 @@ impl<'a> InferenceContext<'a> {
143 .build(); 142 .build();
144 let trait_ref = 143 let trait_ref =
145 TraitRef { trait_id: to_chalk_trait_id(coerce_unsized_trait), substitution: substs }; 144 TraitRef { trait_id: to_chalk_trait_id(coerce_unsized_trait), substitution: substs };
146 let goal = InEnvironment::new(self.trait_env.clone(), Obligation::Trait(trait_ref)); 145 let goal = InEnvironment::new(self.trait_env.clone(), trait_ref.cast(&Interner));
147 146
148 let canonicalizer = self.canonicalizer(); 147 let canonicalizer = self.canonicalizer();
149 let canonicalized = canonicalizer.canonicalize_obligation(goal); 148 let canonicalized = canonicalizer.canonicalize_obligation(goal);
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 93548b6c0..79bbc5dab 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -3,7 +3,7 @@
3use std::iter::{repeat, repeat_with}; 3use std::iter::{repeat, repeat_with};
4use std::{mem, sync::Arc}; 4use std::{mem, sync::Arc};
5 5
6use chalk_ir::{Mutability, TyVariableKind}; 6use chalk_ir::{cast::Cast, Mutability, TyVariableKind};
7use hir_def::{ 7use hir_def::{
8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 8 expr::{Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
9 path::{GenericArg, GenericArgs}, 9 path::{GenericArg, GenericArgs},
@@ -21,7 +21,7 @@ use crate::{
21 to_assoc_type_id, to_chalk_trait_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, DomainGoal, FnPointer, FnSig, Interner, Rawness, Scalar,
25 Substitution, TraitRef, Ty, TyKind, 25 Substitution, TraitRef, Ty, TyKind,
26}; 26};
27 27
@@ -90,10 +90,9 @@ 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 = Obligation::Trait(TraitRef { 93 let implements_fn_trait: DomainGoal =
94 trait_id: to_chalk_trait_id(fn_once_trait), 94 TraitRef { trait_id: to_chalk_trait_id(fn_once_trait), substitution: substs.clone() }
95 substitution: substs.clone(), 95 .cast(&Interner);
96 });
97 let goal = self.canonicalizer().canonicalize_obligation(InEnvironment { 96 let goal = self.canonicalizer().canonicalize_obligation(InEnvironment {
98 value: implements_fn_trait.clone(), 97 value: implements_fn_trait.clone(),
99 environment: trait_env, 98 environment: trait_env,
@@ -938,22 +937,20 @@ impl<'a> InferenceContext<'a> {
938 let generic_predicates = self.db.generic_predicates(def.into()); 937 let generic_predicates = self.db.generic_predicates(def.into());
939 for predicate in generic_predicates.iter() { 938 for predicate in generic_predicates.iter() {
940 let predicate = predicate.clone().subst(parameters); 939 let predicate = predicate.clone().subst(parameters);
941 if let Some(obligation) = Obligation::from_predicate(predicate) { 940 self.obligations.push(predicate.cast(&Interner));
942 self.obligations.push(obligation);
943 }
944 } 941 }
945 // add obligation for trait implementation, if this is a trait method 942 // add obligation for trait implementation, if this is a trait method
946 match def { 943 match def {
947 CallableDefId::FunctionId(f) => { 944 CallableDefId::FunctionId(f) => {
948 if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container 945 if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container
949 { 946 {
950 // construct a TraitDef 947 // construct a TraitRef
951 let substs = 948 let substs =
952 parameters.prefix(generics(self.db.upcast(), trait_.into()).len()); 949 parameters.prefix(generics(self.db.upcast(), trait_.into()).len());
953 self.obligations.push(Obligation::Trait(TraitRef { 950 self.obligations.push(
954 trait_id: to_chalk_trait_id(trait_), 951 TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs }
955 substitution: substs, 952 .cast(&Interner),
956 })); 953 );
957 } 954 }
958 } 955 }
959 CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {} 956 CallableDefId::StructId(_) | CallableDefId::EnumVariantId(_) => {}
diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs
index e15135fc1..58cce56ab 100644
--- a/crates/hir_ty/src/infer/path.rs
+++ b/crates/hir_ty/src/infer/path.rs
@@ -2,6 +2,7 @@
2 2
3use std::iter; 3use std::iter;
4 4
5use chalk_ir::cast::Cast;
5use hir_def::{ 6use hir_def::{
6 path::{Path, PathSegment}, 7 path::{Path, PathSegment},
7 resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs}, 8 resolver::{ResolveValueResult, Resolver, TypeNs, ValueNs},
@@ -256,10 +257,13 @@ impl<'a> InferenceContext<'a> {
256 .push(ty.clone()) 257 .push(ty.clone())
257 .fill(std::iter::repeat_with(|| self.table.new_type_var())) 258 .fill(std::iter::repeat_with(|| self.table.new_type_var()))
258 .build(); 259 .build();
259 self.obligations.push(super::Obligation::Trait(TraitRef { 260 self.obligations.push(
260 trait_id: to_chalk_trait_id(trait_), 261 TraitRef {
261 substitution: trait_substs.clone(), 262 trait_id: to_chalk_trait_id(trait_),
262 })); 263 substitution: trait_substs.clone(),
264 }
265 .cast(&Interner),
266 );
263 Some(trait_substs) 267 Some(trait_substs)
264 } 268 }
265 AssocContainerId::ModuleId(_) => None, 269 AssocContainerId::ModuleId(_) => None,
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs
index 5b7b423fa..1fc03c8f4 100644
--- a/crates/hir_ty/src/infer/unify.rs
+++ b/crates/hir_ty/src/infer/unify.rs
@@ -5,7 +5,7 @@ use std::borrow::Cow;
5use chalk_ir::{FloatTy, IntTy, TyVariableKind}; 5use chalk_ir::{FloatTy, IntTy, TyVariableKind};
6use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; 6use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
7 7
8use super::{InferenceContext, Obligation}; 8use super::{DomainGoal, InferenceContext};
9use crate::{ 9use crate::{
10 AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, InEnvironment, InferenceVar, 10 AliasEq, AliasTy, BoundVar, Canonical, DebruijnIndex, FnPointer, InEnvironment, InferenceVar,
11 Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause, 11 Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, WhereClause,
@@ -87,14 +87,11 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
87 87
88 pub(crate) fn canonicalize_obligation( 88 pub(crate) fn canonicalize_obligation(
89 mut self, 89 mut self,
90 obligation: InEnvironment<Obligation>, 90 obligation: InEnvironment<DomainGoal>,
91 ) -> Canonicalized<InEnvironment<Obligation>> { 91 ) -> Canonicalized<InEnvironment<DomainGoal>> {
92 let result = match obligation.value { 92 let result = match obligation.value {
93 Obligation::Trait(tr) => { 93 DomainGoal::Holds(wc) => {
94 Obligation::Trait(self.do_canonicalize(tr, DebruijnIndex::INNERMOST)) 94 DomainGoal::Holds(self.do_canonicalize(wc, DebruijnIndex::INNERMOST))
95 }
96 Obligation::AliasEq(alias_eq) => {
97 Obligation::AliasEq(self.do_canonicalize(alias_eq, DebruijnIndex::INNERMOST))
98 } 95 }
99 }; 96 };
100 self.into_canonicalized(InEnvironment { 97 self.into_canonicalized(InEnvironment {