diff options
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 79bbc5dab..19249973c 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -11,6 +11,7 @@ use hir_def::{ | |||
11 | AssocContainerId, FieldId, Lookup, | 11 | AssocContainerId, FieldId, Lookup, |
12 | }; | 12 | }; |
13 | use hir_expand::name::{name, Name}; | 13 | use hir_expand::name::{name, Name}; |
14 | use stdx::always; | ||
14 | use syntax::ast::RangeOp; | 15 | use syntax::ast::RangeOp; |
15 | 16 | ||
16 | use crate::{ | 17 | use crate::{ |
@@ -89,12 +90,12 @@ impl<'a> InferenceContext<'a> { | |||
89 | let substs = | 90 | let substs = |
90 | Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); | 91 | Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); |
91 | 92 | ||
92 | let trait_env = Arc::clone(&self.trait_env); | 93 | let trait_env = self.trait_env.env.clone(); |
93 | let implements_fn_trait: DomainGoal = | 94 | let implements_fn_trait: DomainGoal = |
94 | TraitRef { trait_id: to_chalk_trait_id(fn_once_trait), substitution: substs.clone() } | 95 | TraitRef { trait_id: to_chalk_trait_id(fn_once_trait), substitution: substs.clone() } |
95 | .cast(&Interner); | 96 | .cast(&Interner); |
96 | let goal = self.canonicalizer().canonicalize_obligation(InEnvironment { | 97 | let goal = self.canonicalizer().canonicalize_obligation(InEnvironment { |
97 | value: implements_fn_trait.clone(), | 98 | goal: implements_fn_trait.clone(), |
98 | environment: trait_env, | 99 | environment: trait_env, |
99 | }); | 100 | }); |
100 | if self.db.trait_solve(krate, goal.value).is_some() { | 101 | if self.db.trait_solve(krate, goal.value).is_some() { |
@@ -298,8 +299,8 @@ impl<'a> InferenceContext<'a> { | |||
298 | self.db, | 299 | self.db, |
299 | self.resolver.krate(), | 300 | self.resolver.krate(), |
300 | InEnvironment { | 301 | InEnvironment { |
301 | value: canonicalized.value.clone(), | 302 | goal: canonicalized.value.clone(), |
302 | environment: self.trait_env.clone(), | 303 | environment: self.trait_env.env.clone(), |
303 | }, | 304 | }, |
304 | ); | 305 | ); |
305 | let (param_tys, ret_ty): (Vec<Ty>, Ty) = derefs | 306 | let (param_tys, ret_ty): (Vec<Ty>, Ty) = derefs |
@@ -437,8 +438,8 @@ impl<'a> InferenceContext<'a> { | |||
437 | self.db, | 438 | self.db, |
438 | self.resolver.krate(), | 439 | self.resolver.krate(), |
439 | InEnvironment { | 440 | InEnvironment { |
440 | value: canonicalized.value.clone(), | 441 | goal: canonicalized.value.clone(), |
441 | environment: self.trait_env.clone(), | 442 | environment: self.trait_env.env.clone(), |
442 | }, | 443 | }, |
443 | ) | 444 | ) |
444 | .find_map(|derefed_ty| { | 445 | .find_map(|derefed_ty| { |
@@ -513,10 +514,10 @@ impl<'a> InferenceContext<'a> { | |||
513 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 514 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
514 | if let Some(box_) = self.resolve_boxed_box() { | 515 | if let Some(box_) = self.resolve_boxed_box() { |
515 | let mut sb = | 516 | let mut sb = |
516 | Substitution::builder(generics(self.db.upcast(), box_.into()).len()); | 517 | Substitution::build_for_generics(&generics(self.db.upcast(), box_.into())); |
517 | sb = sb.push(inner_ty); | 518 | sb = sb.push(inner_ty); |
518 | match self.db.generic_defaults(box_.into()).as_ref() { | 519 | match self.db.generic_defaults(box_.into()).get(1) { |
519 | [_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => { | 520 | Some(alloc_ty) if !alloc_ty.value.is_unknown() && sb.remaining() > 0 => { |
520 | sb = sb.push(alloc_ty.value.clone()); | 521 | sb = sb.push(alloc_ty.value.clone()); |
521 | } | 522 | } |
522 | _ => (), | 523 | _ => (), |
@@ -537,8 +538,8 @@ impl<'a> InferenceContext<'a> { | |||
537 | self.db, | 538 | self.db, |
538 | krate, | 539 | krate, |
539 | InEnvironment { | 540 | InEnvironment { |
540 | value: &canonicalized.value, | 541 | goal: &canonicalized.value, |
541 | environment: self.trait_env.clone(), | 542 | environment: self.trait_env.env.clone(), |
542 | }, | 543 | }, |
543 | ) { | 544 | ) { |
544 | Some(derefed_ty) => { | 545 | Some(derefed_ty) => { |
@@ -936,7 +937,9 @@ impl<'a> InferenceContext<'a> { | |||
936 | let def: CallableDefId = from_chalk(self.db, *fn_def); | 937 | let def: CallableDefId = from_chalk(self.db, *fn_def); |
937 | let generic_predicates = self.db.generic_predicates(def.into()); | 938 | let generic_predicates = self.db.generic_predicates(def.into()); |
938 | for predicate in generic_predicates.iter() { | 939 | for predicate in generic_predicates.iter() { |
939 | let predicate = predicate.clone().subst(parameters); | 940 | let (predicate, binders) = |
941 | predicate.clone().subst(parameters).into_value_and_skipped_binders(); | ||
942 | always!(binders == 0); // quantified where clauses not yet handled | ||
940 | self.obligations.push(predicate.cast(&Interner)); | 943 | self.obligations.push(predicate.cast(&Interner)); |
941 | } | 944 | } |
942 | // add obligation for trait implementation, if this is a trait method | 945 | // add obligation for trait implementation, if this is a trait method |