Substitution::single -> from1
This commit is contained in:
parent
788533d380
commit
2f5a77658b
@ -180,7 +180,8 @@ impl<'a> InferenceContext<'a> {
|
||||
let inner_ty = self.infer_expr(*body, &Expectation::none());
|
||||
let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body);
|
||||
let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into();
|
||||
TyKind::OpaqueType(opaque_ty_id, Substitution::single(inner_ty)).intern(&Interner)
|
||||
TyKind::OpaqueType(opaque_ty_id, Substitution::from1(&Interner, inner_ty))
|
||||
.intern(&Interner)
|
||||
}
|
||||
Expr::Loop { body, label } => {
|
||||
self.breakables.push(BreakableContext {
|
||||
@ -266,7 +267,8 @@ impl<'a> InferenceContext<'a> {
|
||||
.intern(&Interner);
|
||||
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
||||
let closure_ty =
|
||||
TyKind::Closure(closure_id, Substitution::single(sig_ty)).intern(&Interner);
|
||||
TyKind::Closure(closure_id, Substitution::from1(&Interner, sig_ty))
|
||||
.intern(&Interner);
|
||||
|
||||
// Eagerly try to relate the closure type with the expected
|
||||
// type, otherwise we often won't have enough information to
|
||||
|
@ -31,7 +31,6 @@ mod test_db;
|
||||
use std::sync::Arc;
|
||||
|
||||
use itertools::Itertools;
|
||||
use smallvec::SmallVec;
|
||||
|
||||
use base_db::salsa;
|
||||
use hir_def::{
|
||||
@ -77,14 +76,6 @@ pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
|
||||
pub type FnSig = chalk_ir::FnSig<Interner>;
|
||||
|
||||
impl Substitution {
|
||||
pub fn single(ty: Ty) -> Substitution {
|
||||
Substitution::intern({
|
||||
let mut v = SmallVec::new();
|
||||
v.push(ty.cast(&Interner));
|
||||
v
|
||||
})
|
||||
}
|
||||
|
||||
pub fn prefix(&self, n: usize) -> Substitution {
|
||||
Substitution::intern(self.interned()[..std::cmp::min(self.len(&Interner), n)].into())
|
||||
}
|
||||
|
@ -220,7 +220,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||
let impl_bound = WhereClause::Implemented(TraitRef {
|
||||
trait_id: to_chalk_trait_id(future_trait),
|
||||
// Self type as the first parameter.
|
||||
substitution: Substitution::single(
|
||||
substitution: Substitution::from1(
|
||||
&Interner,
|
||||
TyKind::BoundVar(BoundVar {
|
||||
debruijn: DebruijnIndex::INNERMOST,
|
||||
index: 0,
|
||||
@ -232,7 +233,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||
alias: AliasTy::Projection(ProjectionTy {
|
||||
associated_ty_id: to_assoc_type_id(future_output),
|
||||
// Self type as the first parameter.
|
||||
substitution: Substitution::single(
|
||||
substitution: Substitution::from1(
|
||||
&Interner,
|
||||
TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
|
||||
.intern(&Interner),
|
||||
),
|
||||
|
@ -4,7 +4,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use chalk_ir::{
|
||||
cast::{CastTo, Caster},
|
||||
cast::{Cast, CastTo, Caster},
|
||||
BoundVar, Mutability, Scalar, TyVariableKind,
|
||||
};
|
||||
use smallvec::SmallVec;
|
||||
@ -278,6 +278,14 @@ impl Substitution {
|
||||
self.0.iter()
|
||||
}
|
||||
|
||||
pub fn from1(_interner: &Interner, ty: Ty) -> Substitution {
|
||||
Substitution::intern({
|
||||
let mut v = SmallVec::new();
|
||||
v.push(ty.cast(&Interner));
|
||||
v
|
||||
})
|
||||
}
|
||||
|
||||
pub fn from_iter(
|
||||
interner: &Interner,
|
||||
elements: impl IntoIterator<Item = impl CastTo<GenericArg>>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user