diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir/src/lib.rs | 3 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 7 |
4 files changed, 15 insertions, 11 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 003821981..db4ebada4 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -55,6 +55,7 @@ use hir_ty::{ | |||
55 | autoderef, could_unify, | 55 | autoderef, could_unify, |
56 | method_resolution::{self, TyFingerprint}, | 56 | method_resolution::{self, TyFingerprint}, |
57 | primitive::UintTy, | 57 | primitive::UintTy, |
58 | subst_prefix, | ||
58 | traits::FnTrait, | 59 | traits::FnTrait, |
59 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, | 60 | AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast, |
60 | DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, | 61 | DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution, |
@@ -1503,7 +1504,7 @@ impl TypeParam { | |||
1503 | let krate = self.id.parent.module(db.upcast()).krate(); | 1504 | let krate = self.id.parent.module(db.upcast()).krate(); |
1504 | let ty = params.get(local_idx)?.clone(); | 1505 | let ty = params.get(local_idx)?.clone(); |
1505 | let subst = TyBuilder::type_params_subst(db, self.id.parent); | 1506 | let subst = TyBuilder::type_params_subst(db, self.id.parent); |
1506 | let ty = ty.substitute(&Interner, &subst.prefix(local_idx)); | 1507 | let ty = ty.substitute(&Interner, &subst_prefix(&subst, local_idx)); |
1507 | Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) | 1508 | Some(Type::new_with_resolver_inner(db, krate, &resolver, ty)) |
1508 | } | 1509 | } |
1509 | } | 1510 | } |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 91d657ce2..4ef8024d0 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -19,7 +19,7 @@ use hir_expand::name::Name; | |||
19 | 19 | ||
20 | use crate::{ | 20 | use crate::{ |
21 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, | 21 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, |
22 | lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk, | 22 | lt_from_placeholder_idx, primitive, subst_prefix, to_assoc_type_id, traits::chalk::from_chalk, |
23 | utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg, | 23 | utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg, |
24 | ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, | 24 | ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, |
25 | ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, | 25 | ProjectionTy, ProjectionTyExt, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, |
@@ -484,9 +484,11 @@ impl HirDisplay for Ty { | |||
484 | default_from = i + 1; | 484 | default_from = i + 1; |
485 | } | 485 | } |
486 | (_, Some(default_parameter)) => { | 486 | (_, Some(default_parameter)) => { |
487 | let actual_default = default_parameter | 487 | let actual_default = |
488 | .clone() | 488 | default_parameter.clone().substitute( |
489 | .substitute(&Interner, ¶meters.prefix(i)); | 489 | &Interner, |
490 | &subst_prefix(parameters, i), | ||
491 | ); | ||
490 | if parameter.assert_ty_ref(&Interner) != &actual_default | 492 | if parameter.assert_ty_ref(&Interner) != &actual_default |
491 | { | 493 | { |
492 | default_from = i + 1; | 494 | default_from = i + 1; |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 82ab9c5fe..185a2dfc3 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -964,8 +964,10 @@ impl<'a> InferenceContext<'a> { | |||
964 | if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container | 964 | if let AssocContainerId::TraitId(trait_) = f.lookup(self.db.upcast()).container |
965 | { | 965 | { |
966 | // construct a TraitRef | 966 | // construct a TraitRef |
967 | let substs = | 967 | let substs = crate::subst_prefix( |
968 | parameters.prefix(generics(self.db.upcast(), trait_.into()).len()); | 968 | &*parameters, |
969 | generics(self.db.upcast(), trait_.into()).len(), | ||
970 | ); | ||
969 | self.push_obligation( | 971 | self.push_obligation( |
970 | TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs } | 972 | TraitRef { trait_id: to_chalk_trait_id(trait_), substitution: substs } |
971 | .cast(&Interner), | 973 | .cast(&Interner), |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index abdcf8829..f74b22b58 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -75,10 +75,9 @@ pub type ChalkTraitId = chalk_ir::TraitId<Interner>; | |||
75 | 75 | ||
76 | pub type FnSig = chalk_ir::FnSig<Interner>; | 76 | pub type FnSig = chalk_ir::FnSig<Interner>; |
77 | 77 | ||
78 | impl Substitution { | 78 | // FIXME: get rid of this |
79 | pub fn prefix(&self, n: usize) -> Substitution { | 79 | pub fn subst_prefix(s: &Substitution, n: usize) -> Substitution { |
80 | Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into()) | 80 | Substitution::intern(s.interned()[..std::cmp::min(s.len(&Interner), n)].into()) |
81 | } | ||
82 | } | 81 | } |
83 | 82 | ||
84 | /// Return an index of a parameter in the generic type parameter list by it's id. | 83 | /// Return an index of a parameter in the generic type parameter list by it's id. |