From 2f5a77658baafad1fe3551971ebbcdce87760847 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 5 Apr 2021 21:17:35 +0200 Subject: Substitution::single -> from1 --- crates/hir_ty/src/infer/expr.rs | 6 ++++-- crates/hir_ty/src/lib.rs | 9 --------- crates/hir_ty/src/traits/chalk.rs | 6 ++++-- crates/hir_ty/src/types.rs | 10 +++++++++- 4 files changed, 17 insertions(+), 14 deletions(-) (limited to 'crates') 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> { 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 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; 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; pub type FnSig = chalk_ir::FnSig; 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()) } 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 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 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), ), 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 @@ 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>, -- cgit v1.2.3