From ce2cae45b5242d59b744018dd79bc2ab74670edc Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 15 Mar 2021 21:02:34 +0100 Subject: Rename Substs -> Substitution --- crates/hir_ty/src/autoderef.rs | 4 +- crates/hir_ty/src/display.rs | 4 +- crates/hir_ty/src/infer.rs | 8 +-- crates/hir_ty/src/infer/coerce.rs | 6 +- crates/hir_ty/src/infer/expr.rs | 37 ++++++------ crates/hir_ty/src/infer/pat.rs | 12 ++-- crates/hir_ty/src/infer/path.rs | 20 +++---- crates/hir_ty/src/infer/unify.rs | 16 +++--- crates/hir_ty/src/lib.rs | 94 +++++++++++++++---------------- crates/hir_ty/src/lower.rs | 46 ++++++++------- crates/hir_ty/src/method_resolution.rs | 14 ++--- crates/hir_ty/src/traits.rs | 4 +- crates/hir_ty/src/traits/chalk.rs | 18 +++--- crates/hir_ty/src/traits/chalk/mapping.rs | 15 +++-- 14 files changed, 155 insertions(+), 143 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index 56c6b92d4..bd2ff5d38 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs @@ -15,7 +15,7 @@ use crate::{ to_assoc_type_id, traits::{InEnvironment, Solution}, utils::generics, - BoundVar, Canonical, DebruijnIndex, Interner, Obligation, Substs, TraitRef, Ty, TyKind, + BoundVar, Canonical, DebruijnIndex, Interner, Obligation, Substitution, TraitRef, Ty, TyKind, }; const AUTODEREF_RECURSION_LIMIT: usize = 10; @@ -65,7 +65,7 @@ fn deref_by_trait( // FIXME make the Canonical / bound var handling nicer let parameters = - Substs::build_for_generics(&generic_params).push(ty.value.value.clone()).build(); + Substitution::build_for_generics(&generic_params).push(ty.value.value.clone()).build(); // Check that the type implements Deref at all let trait_ref = TraitRef { trait_: deref_trait, substs: parameters.clone() }; diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index c572bb114..7ce0f864c 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -20,7 +20,7 @@ use crate::{ db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, - ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, + ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, }; pub struct HirFormatter<'a> { @@ -562,7 +562,7 @@ impl HirDisplay for Ty { } TypeParamProvenance::ArgumentImplTrait => { let bounds = f.db.generic_predicates_for_param(id); - let substs = Substs::type_params_for_generics(f.db, &generics); + let substs = Substitution::type_params_for_generics(f.db, &generics); write_bounds_like_dyn_trait_with_prefix( "impl", &bounds.iter().map(|b| b.clone().subst(&substs)).collect::>(), diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 9c385b845..2610c9279 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -38,7 +38,7 @@ use syntax::SmolStr; use super::{ traits::{Guidance, Obligation, ProjectionPredicate, Solution}, - InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, + InEnvironment, ProjectionTy, Substitution, TraitEnvironment, TraitRef, Ty, TypeWalk, }; use crate::{ db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, @@ -390,7 +390,7 @@ impl<'a> InferenceContext<'a> { _ => panic!("resolve_associated_type called with non-associated type"), }; let ty = self.table.new_type_var(); - let substs = Substs::build_for_def(self.db, res_assoc_ty) + let substs = Substitution::build_for_def(self.db, res_assoc_ty) .push(inner_ty) .fill(params.iter().cloned()) .build(); @@ -469,7 +469,7 @@ impl<'a> InferenceContext<'a> { } TypeNs::SelfType(impl_id) => { let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); - let substs = Substs::type_params_for_generics(self.db, &generics); + let substs = Substitution::type_params_for_generics(self.db, &generics); let ty = self.db.impl_self_ty(impl_id).subst(&substs); match unresolved { None => { @@ -496,7 +496,7 @@ impl<'a> InferenceContext<'a> { } } TypeNs::TypeAliasId(it) => { - let substs = Substs::build_for_def(self.db, it) + let substs = Substitution::build_for_def(self.db, it) .fill(std::iter::repeat_with(|| self.table.new_type_var())) .build(); let ty = self.db.ty(it.into()).subst(&substs); diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 137419264..b1f98c507 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -7,7 +7,9 @@ use chalk_ir::{Mutability, TyVariableKind}; use hir_def::lang_item::LangItemTarget; -use crate::{autoderef, traits::Solution, Interner, Obligation, Substs, TraitRef, Ty, TyKind}; +use crate::{ + autoderef, traits::Solution, Interner, Obligation, Substitution, TraitRef, Ty, TyKind, +}; use super::{InEnvironment, InferenceContext}; @@ -134,7 +136,7 @@ impl<'a> InferenceContext<'a> { return None; } - let substs = Substs::build_for_generics(&generic_params) + let substs = Substitution::build_for_generics(&generic_params) .push(from_ty.clone()) .push(to_ty.clone()) .build(); diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index f40dec17f..0be8c5a90 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -21,8 +21,8 @@ use crate::{ to_assoc_type_id, traits::{chalk::from_chalk, FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, Substs, - TraitRef, Ty, TyKind, + AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, + Substitution, TraitRef, Ty, TyKind, }; use super::{ @@ -77,7 +77,7 @@ impl<'a> InferenceContext<'a> { return None; } - let mut param_builder = Substs::builder(num_args); + let mut param_builder = Substitution::builder(num_args); let mut arg_tys = vec![]; for _ in 0..num_args { let arg = self.table.new_type_var(); @@ -87,7 +87,7 @@ impl<'a> InferenceContext<'a> { let parameters = param_builder.build(); let arg_ty = TyKind::Tuple(num_args, parameters).intern(&Interner); let substs = - Substs::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); + Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); let trait_env = Arc::clone(&self.trait_env); let implements_fn_trait = @@ -181,7 +181,7 @@ 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, Substs::single(inner_ty)).intern(&Interner) + TyKind::OpaqueType(opaque_ty_id, Substitution::single(inner_ty)).intern(&Interner) } Expr::Loop { body, label } => { self.breakables.push(BreakableContext { @@ -262,12 +262,12 @@ impl<'a> InferenceContext<'a> { let sig_ty = TyKind::Function(FnPointer { num_args: sig_tys.len() - 1, sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false }, - substs: Substs(sig_tys.clone().into()), + substs: Substitution(sig_tys.clone().into()), }) .intern(&Interner); let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into(); let closure_ty = - TyKind::Closure(closure_id, Substs::single(sig_ty)).intern(&Interner); + TyKind::Closure(closure_id, Substitution::single(sig_ty)).intern(&Interner); // Eagerly try to relate the closure type with the expected // type, otherwise we often won't have enough information to @@ -402,7 +402,7 @@ impl<'a> InferenceContext<'a> { self.unify(&ty, &expected.ty); - let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); + let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); for field in fields.iter() { @@ -511,7 +511,8 @@ impl<'a> InferenceContext<'a> { Expr::Box { expr } => { let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); if let Some(box_) = self.resolve_boxed_box() { - let mut sb = Substs::builder(generics(self.db.upcast(), box_.into()).len()); + let mut sb = + Substitution::builder(generics(self.db.upcast(), box_.into()).len()); sb = sb.push(inner_ty); match self.db.generic_defaults(box_.into()).as_ref() { [_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => { @@ -610,31 +611,31 @@ impl<'a> InferenceContext<'a> { let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); match (range_type, lhs_ty, rhs_ty) { (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { - Some(adt) => Ty::adt_ty(adt, Substs::empty()), + Some(adt) => Ty::adt_ty(adt, Substitution::empty()), None => self.err_ty(), }, (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { - Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), + Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), None => self.err_ty(), }, (RangeOp::Inclusive, None, Some(ty)) => { match self.resolve_range_to_inclusive() { - Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), + Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), None => self.err_ty(), } } (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { - Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), + Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), None => self.err_ty(), }, (RangeOp::Inclusive, Some(_), Some(ty)) => { match self.resolve_range_inclusive() { - Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), + Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), None => self.err_ty(), } } (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { - Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), + Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), None => self.err_ty(), }, (RangeOp::Inclusive, _, None) => self.err_ty(), @@ -681,7 +682,7 @@ impl<'a> InferenceContext<'a> { self.infer_expr_coerce(*expr, &Expectation::has_type(ty.clone())); } - TyKind::Tuple(tys.len(), Substs(tys.into())).intern(&Interner) + TyKind::Tuple(tys.len(), Substitution(tys.into())).intern(&Interner) } Expr::Array(array) => { let elem_ty = match expected.ty.interned(&Interner) { @@ -887,7 +888,7 @@ impl<'a> InferenceContext<'a> { def_generics: Option, generic_args: Option<&GenericArgs>, receiver_ty: &Ty, - ) -> Substs { + ) -> Substitution { let (parent_params, self_params, type_params, impl_trait_params) = def_generics.as_ref().map_or((0, 0, 0, 0), |g| g.provenance_split()); assert_eq!(self_params, 0); // method shouldn't have another Self param @@ -926,7 +927,7 @@ impl<'a> InferenceContext<'a> { substs.push(self.err_ty()); } assert_eq!(substs.len(), total_len); - Substs(substs.into()) + Substitution(substs.into()) } fn register_obligations_for_call(&mut self, callable_ty: &Ty) { diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index 9e8ca18ef..befa0d69b 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs @@ -12,7 +12,9 @@ use hir_def::{ use hir_expand::name::Name; use super::{BindingMode, Expectation, InferenceContext}; -use crate::{lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substs, Ty, TyKind}; +use crate::{ + lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substitution, Ty, TyKind, +}; impl<'a> InferenceContext<'a> { fn infer_tuple_struct_pat( @@ -31,7 +33,7 @@ impl<'a> InferenceContext<'a> { } self.unify(&ty, expected); - let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); + let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); let (pre, post) = match ellipsis { @@ -70,7 +72,7 @@ impl<'a> InferenceContext<'a> { self.unify(&ty, expected); - let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); + let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for subpat in subpats { @@ -138,7 +140,7 @@ impl<'a> InferenceContext<'a> { inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); - TyKind::Tuple(inner_tys.len(), Substs(inner_tys.into())).intern(&Interner) + TyKind::Tuple(inner_tys.len(), Substitution(inner_tys.into())).intern(&Interner) } Pat::Or(ref pats) => { if let Some((first_pat, rest)) = pats.split_first() { @@ -237,7 +239,7 @@ impl<'a> InferenceContext<'a> { }; let inner_ty = self.infer_pat(*inner, &inner_expected, default_bm); - Ty::adt_ty(box_adt, Substs::single(inner_ty)) + Ty::adt_ty(box_adt, Substitution::single(inner_ty)) } None => self.err_ty(), }, diff --git a/crates/hir_ty/src/infer/path.rs b/crates/hir_ty/src/infer/path.rs index af108fb6c..ea01d6238 100644 --- a/crates/hir_ty/src/infer/path.rs +++ b/crates/hir_ty/src/infer/path.rs @@ -9,7 +9,7 @@ use hir_def::{ }; use hir_expand::name::Name; -use crate::{method_resolution, Interner, Substs, Ty, TyKind, ValueTyDefId}; +use crate::{method_resolution, Interner, Substitution, Ty, TyKind, ValueTyDefId}; use super::{ExprOrPatId, InferenceContext, TraitRef}; @@ -79,7 +79,7 @@ impl<'a> InferenceContext<'a> { } ValueNs::ImplSelf(impl_id) => { let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); - let substs = Substs::type_params_for_generics(self.db, &generics); + let substs = Substitution::type_params_for_generics(self.db, &generics); let ty = self.db.impl_self_ty(impl_id).subst(&substs); if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { let ty = self.db.value_ty(struct_id.into()).subst(&substs); @@ -94,10 +94,10 @@ impl<'a> InferenceContext<'a> { let ty = self.db.value_ty(typable); // self_subst is just for the parent - let parent_substs = self_subst.unwrap_or_else(Substs::empty); + let parent_substs = self_subst.unwrap_or_else(Substitution::empty); let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); let substs = ctx.substs_from_path(path, typable, true); - let full_substs = Substs::builder(substs.len()) + let full_substs = Substitution::builder(substs.len()) .use_parent_substs(&parent_substs) .fill(substs.0[parent_substs.len()..].iter().cloned()) .build(); @@ -111,7 +111,7 @@ impl<'a> InferenceContext<'a> { path: &Path, remaining_index: usize, id: ExprOrPatId, - ) -> Option<(ValueNs, Option)> { + ) -> Option<(ValueNs, Option)> { assert!(remaining_index < path.segments().len()); // there may be more intermediate segments between the resolved one and // the end. Only the last segment needs to be resolved to a value; from @@ -164,7 +164,7 @@ impl<'a> InferenceContext<'a> { trait_ref: TraitRef, segment: PathSegment<'_>, id: ExprOrPatId, - ) -> Option<(ValueNs, Option)> { + ) -> Option<(ValueNs, Option)> { let trait_ = trait_ref.trait_; let item = self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { @@ -208,7 +208,7 @@ impl<'a> InferenceContext<'a> { ty: Ty, name: &Name, id: ExprOrPatId, - ) -> Option<(ValueNs, Option)> { + ) -> Option<(ValueNs, Option)> { if let TyKind::Unknown = ty.interned(&Interner) { return None; } @@ -241,7 +241,7 @@ impl<'a> InferenceContext<'a> { }; let substs = match container { AssocContainerId::ImplId(impl_id) => { - let impl_substs = Substs::build_for_def(self.db, impl_id) + let impl_substs = Substitution::build_for_def(self.db, impl_id) .fill(iter::repeat_with(|| self.table.new_type_var())) .build(); let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); @@ -250,7 +250,7 @@ impl<'a> InferenceContext<'a> { } AssocContainerId::TraitId(trait_) => { // we're picking this method - let trait_substs = Substs::build_for_def(self.db, trait_) + let trait_substs = Substitution::build_for_def(self.db, trait_) .push(ty.clone()) .fill(std::iter::repeat_with(|| self.table.new_type_var())) .build(); @@ -274,7 +274,7 @@ impl<'a> InferenceContext<'a> { ty: &Ty, name: &Name, id: ExprOrPatId, - ) -> Option<(ValueNs, Option)> { + ) -> Option<(ValueNs, Option)> { let (enum_id, subst) = match ty.as_adt() { Some((AdtId::EnumId(e), subst)) => (e, subst), _ => return None, diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 7795f446f..b2d4f67b3 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -8,7 +8,7 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use super::{InferenceContext, Obligation}; use crate::{ BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, InEnvironment, InferenceVar, - Interner, Scalar, Substs, Ty, TyKind, TypeWalk, + Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, }; impl<'a> InferenceContext<'a> { @@ -123,10 +123,10 @@ impl Canonicalized { pub(super) fn apply_solution( &self, ctx: &mut InferenceContext<'_>, - solution: Canonical, + solution: Canonical, ) { // the solution may contain new variables, which we need to convert to new inference vars - let new_vars = Substs( + let new_vars = Substitution( solution .kinds .iter() @@ -147,9 +147,9 @@ impl Canonicalized { } } -pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { +pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { let mut table = InferenceTable::new(); - let vars = Substs( + let vars = Substitution( tys.kinds .iter() // we always use type vars here because we want everything to @@ -173,7 +173,7 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { } } Some( - Substs::builder(tys.kinds.len()) + Substitution::builder(tys.kinds.len()) .fill(vars.iter().map(|v| table.resolve_ty_completely(v.clone()))) .build(), ) @@ -264,8 +264,8 @@ impl InferenceTable { pub(crate) fn unify_substs( &mut self, - substs1: &Substs, - substs2: &Substs, + substs1: &Substitution, + substs2: &Substitution, depth: usize, ) -> bool { substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 850385280..52b498ff7 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -67,7 +67,7 @@ pub enum Lifetime { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct OpaqueTy { pub opaque_ty_id: OpaqueTyId, - pub substitution: Substs, + pub substitution: Substitution, } /// A "projection" type corresponds to an (unnormalized) @@ -76,7 +76,7 @@ pub struct OpaqueTy { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct ProjectionTy { pub associated_ty_id: AssocTypeId, - pub substitution: Substs, + pub substitution: Substitution, } impl ProjectionTy { @@ -112,7 +112,7 @@ pub type FnSig = chalk_ir::FnSig; pub struct FnPointer { pub num_args: usize, pub sig: FnSig, - pub substs: Substs, + pub substs: Substitution, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] @@ -137,19 +137,19 @@ pub enum AliasTy { #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub enum TyKind { /// Structures, enumerations and unions. - Adt(AdtId, Substs), + Adt(AdtId, Substitution), /// Represents an associated item like `Iterator::Item`. This is used /// when we have tried to normalize a projection like `T::Item` but /// couldn't find a better representation. In that case, we generate /// an **application type** like `(Iterator::Item)`. - AssociatedType(AssocTypeId, Substs), + AssociatedType(AssocTypeId, Substitution), /// a scalar type like `bool` or `u32` Scalar(Scalar), /// A tuple type. For example, `(i32, bool)`. - Tuple(usize, Substs), + Tuple(usize, Substitution), /// An array with the given length. Written as `[T; n]`. Array(Ty), @@ -169,7 +169,7 @@ pub enum TyKind { /// analogous to the `AssociatedType` type constructor. /// It is also used as the type of async block, with one type parameter /// representing the Future::Output type. - OpaqueType(OpaqueTyId, Substs), + OpaqueType(OpaqueTyId, Substitution), /// The anonymous type of a function declaration/definition. Each /// function has a unique type, which is output (for a function @@ -183,7 +183,7 @@ pub enum TyKind { /// fn foo() -> i32 { 1 } /// let bar = foo; // bar: fn() -> i32 {foo} /// ``` - FnDef(FnDefId, Substs), + FnDef(FnDefId, Substitution), /// The pointee of a string slice. Written as `str`. Str, @@ -195,7 +195,7 @@ pub enum TyKind { /// /// The closure signature is stored in a `FnPtr` type in the first type /// parameter. - Closure(ClosureId, Substs), + Closure(ClosureId, Substitution), /// Represents a foreign type declared in external blocks. ForeignType(ForeignDefId), @@ -273,9 +273,9 @@ impl Ty { /// A list of substitutions for generic parameters. #[derive(Clone, PartialEq, Eq, Debug, Hash)] -pub struct Substs(SmallVec<[Ty; 2]>); +pub struct Substitution(SmallVec<[Ty; 2]>); -impl TypeWalk for Substs { +impl TypeWalk for Substitution { fn walk(&self, f: &mut impl FnMut(&Ty)) { for t in self.0.iter() { t.walk(f); @@ -293,29 +293,29 @@ impl TypeWalk for Substs { } } -impl Substs { +impl Substitution { pub fn interned(&self, _: &Interner) -> &[Ty] { &self.0 } - pub fn empty() -> Substs { - Substs(SmallVec::new()) + pub fn empty() -> Substitution { + Substitution(SmallVec::new()) } - pub fn single(ty: Ty) -> Substs { - Substs({ + pub fn single(ty: Ty) -> Substitution { + Substitution({ let mut v = SmallVec::new(); v.push(ty); v }) } - pub fn prefix(&self, n: usize) -> Substs { - Substs(self.0[..std::cmp::min(self.0.len(), n)].into()) + pub fn prefix(&self, n: usize) -> Substitution { + Substitution(self.0[..std::cmp::min(self.0.len(), n)].into()) } - pub fn suffix(&self, n: usize) -> Substs { - Substs(self.0[self.0.len() - std::cmp::min(self.0.len(), n)..].into()) + pub fn suffix(&self, n: usize) -> Substitution { + Substitution(self.0[self.0.len() - std::cmp::min(self.0.len(), n)..].into()) } pub fn as_single(&self) -> &Ty { @@ -326,15 +326,15 @@ impl Substs { } pub fn from_iter(_interner: &Interner, elements: impl IntoIterator) -> Self { - Substs(elements.into_iter().collect()) + Substitution(elements.into_iter().collect()) } /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). pub(crate) fn type_params_for_generics( db: &dyn HirDatabase, generic_params: &Generics, - ) -> Substs { - Substs( + ) -> Substitution { + Substitution( generic_params .iter() .map(|(id, _)| TyKind::Placeholder(to_placeholder_idx(db, id)).intern(&Interner)) @@ -343,14 +343,14 @@ impl Substs { } /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). - pub fn type_params(db: &dyn HirDatabase, def: impl Into) -> Substs { + pub fn type_params(db: &dyn HirDatabase, def: impl Into) -> Substitution { let params = generics(db.upcast(), def.into()); - Substs::type_params_for_generics(db, ¶ms) + Substitution::type_params_for_generics(db, ¶ms) } /// Return Substs that replace each parameter by a bound variable. - pub(crate) fn bound_vars(generic_params: &Generics, debruijn: DebruijnIndex) -> Substs { - Substs( + pub(crate) fn bound_vars(generic_params: &Generics, debruijn: DebruijnIndex) -> Substitution { + Substitution( generic_params .iter() .enumerate() @@ -363,11 +363,11 @@ impl Substs { let def = def.into(); let params = generics(db.upcast(), def); let param_count = params.len(); - Substs::builder(param_count) + Substitution::builder(param_count) } pub(crate) fn build_for_generics(generic_params: &Generics) -> SubstsBuilder { - Substs::builder(generic_params.len()) + Substitution::builder(generic_params.len()) } fn builder(param_count: usize) -> SubstsBuilder { @@ -387,9 +387,9 @@ pub struct SubstsBuilder { } impl SubstsBuilder { - pub fn build(self) -> Substs { + pub fn build(self) -> Substitution { assert_eq!(self.vec.len(), self.param_count); - Substs(self.vec.into()) + Substitution(self.vec.into()) } pub fn push(mut self, ty: Ty) -> Self { @@ -418,7 +418,7 @@ impl SubstsBuilder { self } - pub fn use_parent_substs(mut self, parent_substs: &Substs) -> Self { + pub fn use_parent_substs(mut self, parent_substs: &Substitution) -> Self { assert!(self.vec.is_empty()); assert!(parent_substs.len() <= self.param_count); self.vec.extend(parent_substs.iter().cloned()); @@ -426,7 +426,7 @@ impl SubstsBuilder { } } -impl Deref for Substs { +impl Deref for Substitution { type Target = [Ty]; fn deref(&self) -> &[Ty] { @@ -466,13 +466,13 @@ impl Binders<&T> { impl Binders { /// Substitutes all variables. - pub fn subst(self, subst: &Substs) -> T { + pub fn subst(self, subst: &Substitution) -> T { assert_eq!(subst.len(), self.num_binders); self.value.subst_bound_vars(subst) } /// Substitutes just a prefix of the variables (shifting the rest). - pub fn subst_prefix(self, subst: &Substs) -> Binders { + pub fn subst_prefix(self, subst: &Substitution) -> Binders { assert!(subst.len() < self.num_binders); Binders::new(self.num_binders - subst.len(), self.value.subst_bound_vars(subst)) } @@ -498,7 +498,7 @@ impl TypeWalk for Binders { pub struct TraitRef { /// FIXME name? pub trait_: TraitId, - pub substs: Substs, + pub substs: Substitution, } impl TraitRef { @@ -618,7 +618,7 @@ impl CallableSig { } } - pub fn from_substs(substs: &Substs) -> CallableSig { + pub fn from_substs(substs: &Substitution) -> CallableSig { CallableSig { params_and_return: substs.iter().cloned().collect(), is_varargs: false } } @@ -651,10 +651,10 @@ impl TypeWalk for CallableSig { impl Ty { pub fn unit() -> Self { - TyKind::Tuple(0, Substs::empty()).intern(&Interner) + TyKind::Tuple(0, Substitution::empty()).intern(&Interner) } - pub fn adt_ty(adt: hir_def::AdtId, substs: Substs) -> Ty { + pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty { TyKind::Adt(AdtId(adt), substs).intern(&Interner) } @@ -662,7 +662,7 @@ impl Ty { TyKind::Function(FnPointer { num_args: sig.params().len(), sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, - substs: Substs::from_iter(&Interner, sig.params_and_return.iter().cloned()), + substs: Substitution::from_iter(&Interner, sig.params_and_return.iter().cloned()), }) .intern(&Interner) } @@ -709,14 +709,14 @@ impl Ty { t } - pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substs)> { + pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> { match self.interned(&Interner) { TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)), _ => None, } } - pub fn as_tuple(&self) -> Option<&Substs> { + pub fn as_tuple(&self) -> Option<&Substitution> { match self.interned(&Interner) { TyKind::Tuple(_, substs) => Some(substs), _ => None, @@ -828,7 +828,7 @@ impl Ty { /// Returns the type parameters of this type if it has some (i.e. is an ADT /// or function); so if `self` is `Option`, this returns the `u32`. - pub fn substs(&self) -> Option<&Substs> { + pub fn substs(&self) -> Option<&Substitution> { match self.interned(&Interner) { TyKind::Adt(_, substs) | TyKind::FnDef(_, substs) @@ -841,7 +841,7 @@ impl Ty { } } - fn substs_mut(&mut self) -> Option<&mut Substs> { + fn substs_mut(&mut self) -> Option<&mut Substitution> { match self.interned_mut() { TyKind::Adt(_, substs) | TyKind::FnDef(_, substs) @@ -869,7 +869,7 @@ impl Ty { // So just provide the Future trait. let impl_bound = GenericPredicate::Implemented(TraitRef { trait_: future_trait, - substs: Substs::empty(), + substs: Substitution::empty(), }); Some(vec![impl_bound]) } else { @@ -992,7 +992,7 @@ pub trait TypeWalk { } /// Substitutes `TyKind::Bound` vars with the given substitution. - fn subst_bound_vars(self, substs: &Substs) -> Self + fn subst_bound_vars(self, substs: &Substitution) -> Self where Self: Sized, { @@ -1000,7 +1000,7 @@ pub trait TypeWalk { } /// Substitutes `TyKind::Bound` vars with the given substitution. - fn subst_bound_vars_at_depth(mut self, substs: &Substs, depth: DebruijnIndex) -> Self + fn subst_bound_vars_at_depth(mut self, substs: &Substitution, depth: DebruijnIndex) -> Self where Self: Sized, { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 6ab757bfc..462882b2b 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -35,7 +35,7 @@ use crate::{ }, AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, - ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, + ReturnTypeImplTraits, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, }; #[derive(Debug)] @@ -151,7 +151,7 @@ impl<'a> TyLoweringContext<'a> { TypeRef::Never => TyKind::Never.intern(&Interner), TypeRef::Tuple(inner) => { let inner_tys = inner.iter().map(|tr| self.lower_ty(tr)); - TyKind::Tuple(inner_tys.len(), Substs::from_iter(&Interner, inner_tys)) + TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys)) .intern(&Interner) } TypeRef::Path(path) => { @@ -177,7 +177,7 @@ impl<'a> TyLoweringContext<'a> { } TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), TypeRef::Fn(params, is_varargs) => { - let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); + let substs = Substitution(params.iter().map(|tr| self.lower_ty(tr)).collect()); TyKind::Function(FnPointer { num_args: substs.len() - 1, sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, @@ -228,7 +228,7 @@ impl<'a> TyLoweringContext<'a> { let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); let generics = generics(self.db.upcast(), func.into()); - let parameters = Substs::bound_vars(&generics, self.in_binders); + let parameters = Substitution::bound_vars(&generics, self.in_binders); TyKind::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id, substitution: parameters, @@ -398,10 +398,10 @@ impl<'a> TyLoweringContext<'a> { let generics = generics(self.db.upcast(), impl_id.into()); let substs = match self.type_param_mode { TypeParamLoweringMode::Placeholder => { - Substs::type_params_for_generics(self.db, &generics) + Substitution::type_params_for_generics(self.db, &generics) } TypeParamLoweringMode::Variable => { - Substs::bound_vars(&generics, self.in_binders) + Substitution::bound_vars(&generics, self.in_binders) } }; self.db.impl_self_ty(impl_id).subst(&substs) @@ -410,10 +410,10 @@ impl<'a> TyLoweringContext<'a> { let generics = generics(self.db.upcast(), adt.into()); let substs = match self.type_param_mode { TypeParamLoweringMode::Placeholder => { - Substs::type_params_for_generics(self.db, &generics) + Substitution::type_params_for_generics(self.db, &generics) } TypeParamLoweringMode::Variable => { - Substs::bound_vars(&generics, self.in_binders) + Substitution::bound_vars(&generics, self.in_binders) } }; self.db.ty(adt.into()).subst(&substs) @@ -464,7 +464,7 @@ impl<'a> TyLoweringContext<'a> { TypeParamLoweringMode::Placeholder => { // if we're lowering to placeholders, we have to put // them in now - let s = Substs::type_params( + let s = Substitution::type_params( self.db, self.resolver.generic_def().expect( "there should be generics if there's a generic param", @@ -522,7 +522,7 @@ impl<'a> TyLoweringContext<'a> { // special-case enum variants resolved: ValueTyDefId, infer_args: bool, - ) -> Substs { + ) -> Substitution { let last = path.segments().last().expect("path should have at least one segment"); let (segment, generic_def) = match resolved { ValueTyDefId::FunctionId(it) => (last, Some(it.into())), @@ -553,7 +553,7 @@ impl<'a> TyLoweringContext<'a> { segment: PathSegment<'_>, def_generic: Option, infer_args: bool, - ) -> Substs { + ) -> Substitution { let mut substs = Vec::new(); let def_generics = def_generic.map(|def| generics(self.db.upcast(), def)); @@ -601,7 +601,7 @@ impl<'a> TyLoweringContext<'a> { for default_ty in defaults.iter().skip(substs.len()) { // each default can depend on the previous parameters - let substs_so_far = Substs(substs.clone().into()); + let substs_so_far = Substitution(substs.clone().into()); substs.push(default_ty.clone().subst(&substs_so_far)); } } @@ -614,7 +614,7 @@ impl<'a> TyLoweringContext<'a> { } assert_eq!(substs.len(), total_len); - Substs(substs.into()) + Substitution(substs.into()) } fn lower_trait_ref_from_path( @@ -656,7 +656,11 @@ impl<'a> TyLoweringContext<'a> { self.lower_trait_ref_from_path(path, explicit_self_ty) } - fn trait_ref_substs_from_path(&self, segment: PathSegment<'_>, resolved: TraitId) -> Substs { + fn trait_ref_substs_from_path( + &self, + segment: PathSegment<'_>, + resolved: TraitId, + ) -> Substitution { self.substs_from_path_segment(segment, Some(resolved.into()), false) } @@ -817,7 +821,7 @@ pub fn associated_type_shorthand_candidates( { let trait_ref = TraitRef { trait_: trait_id, - substs: Substs::bound_vars(&generics, DebruijnIndex::INNERMOST), + substs: Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST), }; traits_.push(trait_ref); } @@ -945,7 +949,7 @@ pub(crate) fn trait_environment_query( // function default implementations (and hypothetical code // inside consts or type aliases) cov_mark::hit!(trait_self_implements_self); - let substs = Substs::type_params(db, trait_id); + let substs = Substitution::type_params(db, trait_id); let trait_ref = TraitRef { trait_: trait_id, substs }; let pred = GenericPredicate::Implemented(trait_ref); let program_clause: chalk_ir::ProgramClause = @@ -1033,7 +1037,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { /// function body. fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders { let generics = generics(db.upcast(), def.into()); - let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); + let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); Binders::new( substs.len(), TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner), @@ -1078,7 +1082,7 @@ fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders Binders { let generics = generics(db.upcast(), adt.into()); - let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); + let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); Binders::new(substs.len(), Ty::adt_ty(adt, substs)) } @@ -1126,7 +1130,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders { if db.type_alias_data(t).is_extern { Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner)) } else { - let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); + let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); let type_ref = &db.type_alias_data(t).type_ref; let inner = ctx.lower_ty(type_ref.as_ref().unwrap_or(&TypeRef::Error)); Binders::new(substs.len(), inner) diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index be72c4a1c..943d3339b 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs @@ -21,7 +21,7 @@ use crate::{ primitive::{self, FloatTy, IntTy, UintTy}, utils::all_super_traits, AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner, - Scalar, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, + Scalar, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, }; /// This is used as a key for indexing impls. @@ -672,10 +672,10 @@ pub(crate) fn inherent_impl_substs( db: &dyn HirDatabase, impl_id: ImplId, self_ty: &Canonical, -) -> Option { +) -> Option { // we create a var for each type parameter of the impl; we need to keep in // mind here that `self_ty` might have vars of its own - let vars = Substs::build_for_def(db, impl_id) + let vars = Substitution::build_for_def(db, impl_id) .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.kinds.len()) .build(); let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); @@ -693,7 +693,7 @@ pub(crate) fn inherent_impl_substs( /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past /// num_vars_to_keep) by `TyKind::Unknown`. -fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { +fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution { s.fold_binders( &mut |ty, binders| { if let TyKind::BoundVar(bound) = ty.interned(&Interner) { @@ -716,13 +716,13 @@ fn transform_receiver_ty( self_ty: &Canonical, ) -> Option { let substs = match function_id.lookup(db.upcast()).container { - AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) + AssocContainerId::TraitId(_) => Substitution::build_for_def(db, function_id) .push(self_ty.value.clone()) .fill_with_unknown() .build(), AssocContainerId::ImplId(impl_id) => { let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; - Substs::build_for_def(db, function_id) + Substitution::build_for_def(db, function_id) .use_parent_substs(&impl_substs) .fill_with_unknown() .build() @@ -768,7 +768,7 @@ fn generic_implements_goal( self_ty: Canonical, ) -> Canonical> { let mut kinds = self_ty.kinds.to_vec(); - let substs = super::Substs::build_for_def(db, trait_) + let substs = super::Substitution::build_for_def(db, trait_) .push(self_ty.value) .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) .build(); diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index a6a63c673..40eb1034e 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs @@ -8,7 +8,7 @@ use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver}; use hir_def::{lang_item::LangItemTarget, TraitId}; use stdx::panic_context; -use crate::{db::HirDatabase, DebruijnIndex, Substs}; +use crate::{db::HirDatabase, DebruijnIndex, Substitution}; use super::{ Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TyKind, TypeWalk, @@ -252,7 +252,7 @@ fn solution_from_chalk( } #[derive(Clone, Debug, PartialEq, Eq)] -pub struct SolutionVariables(pub Canonical); +pub struct SolutionVariables(pub Canonical); #[derive(Clone, Debug, PartialEq, Eq)] /// A (possible) solution for a proposed goal. diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 4bd8ba303..bef6e7e9c 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -22,7 +22,7 @@ use crate::{ to_assoc_type_id, utils::generics, BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate, - ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TyKind, + ProjectionPredicate, ProjectionTy, Substitution, TraitRef, Ty, TyKind, }; use mapping::{ convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, @@ -221,7 +221,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { let impl_bound = GenericPredicate::Implemented(TraitRef { trait_: future_trait, // Self type as the first parameter. - substs: Substs::single( + substs: Substitution::single( TyKind::BoundVar(BoundVar { debruijn: DebruijnIndex::INNERMOST, index: 0, @@ -236,7 +236,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { projection_ty: ProjectionTy { associated_ty_id: to_assoc_type_id(future_output), // Self type as the first parameter. - substitution: Substs::single( + substitution: Substitution::single( TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) .intern(&Interner), ), @@ -313,7 +313,7 @@ impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { _closure_id: chalk_ir::ClosureId, _substs: &chalk_ir::Substitution, ) -> chalk_ir::Substitution { - Substs::empty().to_chalk(self.db) + Substitution::empty().to_chalk(self.db) } fn trait_name(&self, trait_id: chalk_ir::TraitId) -> String { @@ -392,7 +392,7 @@ pub(crate) fn associated_ty_data_query( // Lower bounds -- we could/should maybe move this to a separate query in `lower` let type_alias_data = db.type_alias_data(type_alias); let generic_params = generics(db.upcast(), type_alias.into()); - let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); + let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); let ctx = crate::TyLoweringContext::new(db, &resolver) .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); @@ -427,7 +427,7 @@ pub(crate) fn trait_datum_query( let trait_data = db.trait_data(trait_); debug!("trait {:?} = {:?}", trait_id, trait_data.name); let generic_params = generics(db.upcast(), trait_.into()); - let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); + let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let flags = rust_ir::TraitFlags { auto: trait_data.is_auto, upstream: trait_.lookup(db.upcast()).container.krate() != krate, @@ -496,7 +496,7 @@ pub(crate) fn struct_datum_query( let upstream = adt_id.module(db.upcast()).krate() != krate; let where_clauses = { let generic_params = generics(db.upcast(), adt_id.into()); - let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); + let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); convert_where_clauses(db, adt_id.into(), &bound_vars) }; let flags = rust_ir::AdtFlags { @@ -545,7 +545,7 @@ fn impl_def_datum( let impl_data = db.impl_data(impl_id); let generic_params = generics(db.upcast(), impl_id.into()); - let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); + let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let trait_ = trait_ref.trait_; let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { rust_ir::ImplType::Local @@ -635,7 +635,7 @@ pub(crate) fn fn_def_datum_query( let callable_def: CallableDefId = from_chalk(db, fn_def_id); let generic_params = generics(db.upcast(), callable_def.into()); let sig = db.callable_item_signature(callable_def); - let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); + let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); let bound = rust_ir::FnDefDatumBound { // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 6a8b6752e..524814f43 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -15,7 +15,7 @@ use crate::{ primitive::UintTy, traits::{Canonical, Obligation}, AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, - ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, + ProjectionPredicate, ProjectionTy, Scalar, Substitution, TraitRef, Ty, }; use super::interner::*; @@ -134,7 +134,7 @@ impl ToChalk for Ty { .. }) => { assert_eq!(num_binders, 0); - let substs: Substs = from_chalk( + let substs: Substitution = from_chalk( db, substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), ); @@ -213,14 +213,17 @@ fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty { chalk_ir::TyKind::Array(arg, const_).intern(&Interner) } -impl ToChalk for Substs { +impl ToChalk for Substitution { type Chalk = chalk_ir::Substitution; fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution { chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) } - fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution) -> Substs { + fn from_chalk( + db: &dyn HirDatabase, + parameters: chalk_ir::Substitution, + ) -> Substitution { let tys = parameters .iter(&Interner) .map(|p| match p.ty(&Interner) { @@ -228,7 +231,7 @@ impl ToChalk for Substs { None => unimplemented!(), }) .collect(); - Substs(tys) + Substitution(tys) } } @@ -489,7 +492,7 @@ where pub(super) fn convert_where_clauses( db: &dyn HirDatabase, def: GenericDefId, - substs: &Substs, + substs: &Substitution, ) -> Vec> { let generic_predicates = db.generic_predicates(def); let mut result = Vec::with_capacity(generic_predicates.len()); -- cgit v1.2.3