diff options
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r-- | crates/hir_ty/src/infer.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 497a1beb7..1b1d4458c 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -38,11 +38,11 @@ use syntax::SmolStr; | |||
38 | 38 | ||
39 | use super::{ | 39 | use super::{ |
40 | traits::{DomainGoal, Guidance, Solution}, | 40 | traits::{DomainGoal, Guidance, Solution}, |
41 | InEnvironment, ProjectionTy, Substitution, TraitEnvironment, TraitRef, Ty, TypeWalk, | 41 | InEnvironment, ProjectionTy, TraitEnvironment, TraitRef, Ty, TypeWalk, |
42 | }; | 42 | }; |
43 | use crate::{ | 43 | use crate::{ |
44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, | 44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, |
45 | to_assoc_type_id, to_chalk_trait_id, AliasEq, AliasTy, Interner, TyKind, | 45 | to_assoc_type_id, AliasEq, AliasTy, Interner, TyBuilder, TyKind, |
46 | }; | 46 | }; |
47 | 47 | ||
48 | // This lint has a false positive here. See the link below for details. | 48 | // This lint has a false positive here. See the link below for details. |
@@ -325,7 +325,7 @@ impl<'a> InferenceContext<'a> { | |||
325 | 325 | ||
326 | /// Replaces Ty::Unknown by a new type var, so we can maybe still infer it. | 326 | /// Replaces Ty::Unknown by a new type var, so we can maybe still infer it. |
327 | fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty { | 327 | fn insert_type_vars_shallow(&mut self, ty: Ty) -> Ty { |
328 | match ty.interned(&Interner) { | 328 | match ty.kind(&Interner) { |
329 | TyKind::Unknown => self.table.new_type_var(), | 329 | TyKind::Unknown => self.table.new_type_var(), |
330 | _ => ty, | 330 | _ => ty, |
331 | } | 331 | } |
@@ -340,6 +340,8 @@ impl<'a> InferenceContext<'a> { | |||
340 | // no change | 340 | // no change |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | let _span = profile::span("resolve_obligations_as_possible"); | ||
344 | |||
343 | self.last_obligations_check = Some(self.table.revision); | 345 | self.last_obligations_check = Some(self.table.revision); |
344 | let obligations = mem::replace(&mut self.obligations, Vec::new()); | 346 | let obligations = mem::replace(&mut self.obligations, Vec::new()); |
345 | for obligation in obligations { | 347 | for obligation in obligations { |
@@ -407,16 +409,14 @@ impl<'a> InferenceContext<'a> { | |||
407 | _ => panic!("resolve_associated_type called with non-associated type"), | 409 | _ => panic!("resolve_associated_type called with non-associated type"), |
408 | }; | 410 | }; |
409 | let ty = self.table.new_type_var(); | 411 | let ty = self.table.new_type_var(); |
410 | let substs = Substitution::build_for_def(self.db, res_assoc_ty) | 412 | let trait_ref = TyBuilder::trait_ref(self.db, trait_) |
411 | .push(inner_ty) | 413 | .push(inner_ty) |
412 | .fill(params.iter().cloned()) | 414 | .fill(params.iter().cloned()) |
413 | .build(); | 415 | .build(); |
414 | let trait_ref = | ||
415 | TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs.clone() }; | ||
416 | let alias_eq = AliasEq { | 416 | let alias_eq = AliasEq { |
417 | alias: AliasTy::Projection(ProjectionTy { | 417 | alias: AliasTy::Projection(ProjectionTy { |
418 | associated_ty_id: to_assoc_type_id(res_assoc_ty), | 418 | associated_ty_id: to_assoc_type_id(res_assoc_ty), |
419 | substitution: substs, | 419 | substitution: trait_ref.substitution.clone(), |
420 | }), | 420 | }), |
421 | ty: ty.clone(), | 421 | ty: ty.clone(), |
422 | }; | 422 | }; |
@@ -436,7 +436,7 @@ impl<'a> InferenceContext<'a> { | |||
436 | /// to do it as well. | 436 | /// to do it as well. |
437 | fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty { | 437 | fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty { |
438 | let ty = self.resolve_ty_as_possible(ty); | 438 | let ty = self.resolve_ty_as_possible(ty); |
439 | ty.fold(&mut |ty| match ty.interned(&Interner) { | 439 | ty.fold(&mut |ty| match ty.kind(&Interner) { |
440 | TyKind::Alias(AliasTy::Projection(proj_ty)) => { | 440 | TyKind::Alias(AliasTy::Projection(proj_ty)) => { |
441 | self.normalize_projection_ty(proj_ty.clone()) | 441 | self.normalize_projection_ty(proj_ty.clone()) |
442 | } | 442 | } |
@@ -487,7 +487,7 @@ impl<'a> InferenceContext<'a> { | |||
487 | } | 487 | } |
488 | TypeNs::SelfType(impl_id) => { | 488 | TypeNs::SelfType(impl_id) => { |
489 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); | 489 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
490 | let substs = Substitution::type_params_for_generics(self.db, &generics); | 490 | let substs = generics.type_params_subst(self.db); |
491 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 491 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
492 | match unresolved { | 492 | match unresolved { |
493 | None => { | 493 | None => { |
@@ -514,10 +514,9 @@ impl<'a> InferenceContext<'a> { | |||
514 | } | 514 | } |
515 | } | 515 | } |
516 | TypeNs::TypeAliasId(it) => { | 516 | TypeNs::TypeAliasId(it) => { |
517 | let substs = Substitution::build_for_def(self.db, it) | 517 | let ty = TyBuilder::def_ty(self.db, it.into()) |
518 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) | 518 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) |
519 | .build(); | 519 | .build(); |
520 | let ty = self.db.ty(it.into()).subst(&substs); | ||
521 | let variant = ty_variant(&ty); | 520 | let variant = ty_variant(&ty); |
522 | forbid_unresolved_segments((ty, variant), unresolved) | 521 | forbid_unresolved_segments((ty, variant), unresolved) |
523 | } | 522 | } |