aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-04-05 20:17:35 +0100
committerFlorian Diebold <[email protected]>2021-04-05 20:58:03 +0100
commit2f5a77658baafad1fe3551971ebbcdce87760847 (patch)
tree940789c56348e2994d8941136fbc2f5dfc90fbc2 /crates/hir_ty/src
parent788533d38091472ed05c8b55fd7a2002c49f4eb7 (diff)
Substitution::single -> from1
Diffstat (limited to 'crates/hir_ty/src')
-rw-r--r--crates/hir_ty/src/infer/expr.rs6
-rw-r--r--crates/hir_ty/src/lib.rs9
-rw-r--r--crates/hir_ty/src/traits/chalk.rs6
-rw-r--r--crates/hir_ty/src/types.rs10
4 files changed, 17 insertions, 14 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 56a9365cb..82ab9c5fe 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -180,7 +180,8 @@ impl<'a> InferenceContext<'a> {
180 let inner_ty = self.infer_expr(*body, &Expectation::none()); 180 let inner_ty = self.infer_expr(*body, &Expectation::none());
181 let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body); 181 let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body);
182 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); 182 let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
183 TyKind::OpaqueType(opaque_ty_id, Substitution::single(inner_ty)).intern(&Interner) 183 TyKind::OpaqueType(opaque_ty_id, Substitution::from1(&Interner, inner_ty))
184 .intern(&Interner)
184 } 185 }
185 Expr::Loop { body, label } => { 186 Expr::Loop { body, label } => {
186 self.breakables.push(BreakableContext { 187 self.breakables.push(BreakableContext {
@@ -266,7 +267,8 @@ impl<'a> InferenceContext<'a> {
266 .intern(&Interner); 267 .intern(&Interner);
267 let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into(); 268 let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
268 let closure_ty = 269 let closure_ty =
269 TyKind::Closure(closure_id, Substitution::single(sig_ty)).intern(&Interner); 270 TyKind::Closure(closure_id, Substitution::from1(&Interner, sig_ty))
271 .intern(&Interner);
270 272
271 // Eagerly try to relate the closure type with the expected 273 // Eagerly try to relate the closure type with the expected
272 // type, otherwise we often won't have enough information to 274 // type, otherwise we often won't have enough information to
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index 928dd76e5..6d5123cf1 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -31,7 +31,6 @@ mod test_db;
31use std::sync::Arc; 31use std::sync::Arc;
32 32
33use itertools::Itertools; 33use itertools::Itertools;
34use smallvec::SmallVec;
35 34
36use base_db::salsa; 35use base_db::salsa;
37use hir_def::{ 36use hir_def::{
@@ -77,14 +76,6 @@ pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
77pub type FnSig = chalk_ir::FnSig<Interner>; 76pub type FnSig = chalk_ir::FnSig<Interner>;
78 77
79impl Substitution { 78impl Substitution {
80 pub fn single(ty: Ty) -> Substitution {
81 Substitution::intern({
82 let mut v = SmallVec::new();
83 v.push(ty.cast(&Interner));
84 v
85 })
86 }
87
88 pub fn prefix(&self, n: usize) -> Substitution { 79 pub fn prefix(&self, n: usize) -> Substitution {
89 Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into()) 80 Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
90 } 81 }
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs
index dff87ef70..075e82f4b 100644
--- a/crates/hir_ty/src/traits/chalk.rs
+++ b/crates/hir_ty/src/traits/chalk.rs
@@ -220,7 +220,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
220 let impl_bound = WhereClause::Implemented(TraitRef { 220 let impl_bound = WhereClause::Implemented(TraitRef {
221 trait_id: to_chalk_trait_id(future_trait), 221 trait_id: to_chalk_trait_id(future_trait),
222 // Self type as the first parameter. 222 // Self type as the first parameter.
223 substitution: Substitution::single( 223 substitution: Substitution::from1(
224 &Interner,
224 TyKind::BoundVar(BoundVar { 225 TyKind::BoundVar(BoundVar {
225 debruijn: DebruijnIndex::INNERMOST, 226 debruijn: DebruijnIndex::INNERMOST,
226 index: 0, 227 index: 0,
@@ -232,7 +233,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
232 alias: AliasTy::Projection(ProjectionTy { 233 alias: AliasTy::Projection(ProjectionTy {
233 associated_ty_id: to_assoc_type_id(future_output), 234 associated_ty_id: to_assoc_type_id(future_output),
234 // Self type as the first parameter. 235 // Self type as the first parameter.
235 substitution: Substitution::single( 236 substitution: Substitution::from1(
237 &Interner,
236 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) 238 TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
237 .intern(&Interner), 239 .intern(&Interner),
238 ), 240 ),
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs
index bd89991dc..6dffda1ca 100644
--- a/crates/hir_ty/src/types.rs
+++ b/crates/hir_ty/src/types.rs
@@ -4,7 +4,7 @@
4use std::sync::Arc; 4use std::sync::Arc;
5 5
6use chalk_ir::{ 6use chalk_ir::{
7 cast::{CastTo, Caster}, 7 cast::{Cast, CastTo, Caster},
8 BoundVar, Mutability, Scalar, TyVariableKind, 8 BoundVar, Mutability, Scalar, TyVariableKind,
9}; 9};
10use smallvec::SmallVec; 10use smallvec::SmallVec;
@@ -278,6 +278,14 @@ impl Substitution {
278 self.0.iter() 278 self.0.iter()
279 } 279 }
280 280
281 pub fn from1(_interner: &Interner, ty: Ty) -> Substitution {
282 Substitution::intern({
283 let mut v = SmallVec::new();
284 v.push(ty.cast(&Interner));
285 v
286 })
287 }
288
281 pub fn from_iter( 289 pub fn from_iter(
282 interner: &Interner, 290 interner: &Interner,
283 elements: impl IntoIterator<Item = impl CastTo<GenericArg>>, 291 elements: impl IntoIterator<Item = impl CastTo<GenericArg>>,