aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-05 20:56:40 +0100
committerFlorian Diebold <[email protected]>2021-04-05 20:58:53 +0100
commitb67148daea86d85d211c4243f22635d6ac7e1983 (patch)
tree0f666c5b917de8a0f2ebf5fba185500d153036f3 /crates/hir_ty
parent2a83645e1bb01578c4bbe5f71418d354108dfd77 (diff)
Substitution::prefix -> subst_prefix
I probably want to get rid of this function completely later.
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/display.rs10
-rw-r--r--crates/hir_ty/src/infer/expr.rs6
-rw-r--r--crates/hir_ty/src/lib.rs7
3 files changed, 13 insertions, 10 deletions
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
20use crate::{ 20use 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, &parameters.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
76pub type FnSig = chalk_ir::FnSig<Interner>; 76pub type FnSig = chalk_ir::FnSig<Interner>;
77 77
78impl Substitution { 78// FIXME: get rid of this
79 pub fn prefix(&self, n: usize) -> Substitution { 79pub 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.