Skip to content

Commit 2f5a776

Browse files
committed
Substitution::single -> from1
1 parent 788533d commit 2f5a776

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

crates/hir_ty/src/infer/expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ impl<'a> InferenceContext<'a> {
180180
let inner_ty = self.infer_expr(*body, &Expectation::none());
181181
let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body);
182182
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)
184185
}
185186
Expr::Loop { body, label } => {
186187
self.breakables.push(BreakableContext {
@@ -266,7 +267,8 @@ impl<'a> InferenceContext<'a> {
266267
.intern(&Interner);
267268
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
268269
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);
270272

271273
// Eagerly try to relate the closure type with the expected
272274
// type, otherwise we often won't have enough information to

crates/hir_ty/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ mod test_db;
3131
use std::sync::Arc;
3232

3333
use itertools::Itertools;
34-
use smallvec::SmallVec;
3534

3635
use base_db::salsa;
3736
use hir_def::{
@@ -77,14 +76,6 @@ pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
7776
pub type FnSig = chalk_ir::FnSig<Interner>;
7877

7978
impl 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-
8879
pub fn prefix(&self, n: usize) -> Substitution {
8980
Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
9081
}

crates/hir_ty/src/traits/chalk.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
220220
let impl_bound = WhereClause::Implemented(TraitRef {
221221
trait_id: to_chalk_trait_id(future_trait),
222222
// Self type as the first parameter.
223-
substitution: Substitution::single(
223+
substitution: Substitution::from1(
224+
&Interner,
224225
TyKind::BoundVar(BoundVar {
225226
debruijn: DebruijnIndex::INNERMOST,
226227
index: 0,
@@ -232,7 +233,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
232233
alias: AliasTy::Projection(ProjectionTy {
233234
associated_ty_id: to_assoc_type_id(future_output),
234235
// Self type as the first parameter.
235-
substitution: Substitution::single(
236+
substitution: Substitution::from1(
237+
&Interner,
236238
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
237239
.intern(&Interner),
238240
),

crates/hir_ty/src/types.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::sync::Arc;
55

66
use chalk_ir::{
7-
cast::{CastTo, Caster},
7+
cast::{Cast, CastTo, Caster},
88
BoundVar, Mutability, Scalar, TyVariableKind,
99
};
1010
use smallvec::SmallVec;
@@ -278,6 +278,14 @@ impl Substitution {
278278
self.0.iter()
279279
}
280280

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+
281289
pub fn from_iter(
282290
interner: &Interner,
283291
elements: impl IntoIterator<Item = impl CastTo<GenericArg>>,

0 commit comments

Comments
 (0)