diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/autoderef.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/unsafe_check.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 207 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 37 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 12 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/path.rs | 20 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 94 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 46 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 14 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 16 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 20 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 15 |
17 files changed, 371 insertions, 156 deletions
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::{ | |||
15 | to_assoc_type_id, | 15 | to_assoc_type_id, |
16 | traits::{InEnvironment, Solution}, | 16 | traits::{InEnvironment, Solution}, |
17 | utils::generics, | 17 | utils::generics, |
18 | BoundVar, Canonical, DebruijnIndex, Interner, Obligation, Substs, TraitRef, Ty, TyKind, | 18 | BoundVar, Canonical, DebruijnIndex, Interner, Obligation, Substitution, TraitRef, Ty, TyKind, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | const AUTODEREF_RECURSION_LIMIT: usize = 10; | 21 | const AUTODEREF_RECURSION_LIMIT: usize = 10; |
@@ -65,7 +65,7 @@ fn deref_by_trait( | |||
65 | // FIXME make the Canonical / bound var handling nicer | 65 | // FIXME make the Canonical / bound var handling nicer |
66 | 66 | ||
67 | let parameters = | 67 | let parameters = |
68 | Substs::build_for_generics(&generic_params).push(ty.value.value.clone()).build(); | 68 | Substitution::build_for_generics(&generic_params).push(ty.value.value.clone()).build(); |
69 | 69 | ||
70 | // Check that the type implements Deref at all | 70 | // Check that the type implements Deref at all |
71 | let trait_ref = TraitRef { trait_: deref_trait, substs: parameters.clone() }; | 71 | let trait_ref = TraitRef { trait_: deref_trait, substs: parameters.clone() }; |
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 3605ca581..982ad5b9e 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs | |||
@@ -91,7 +91,7 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
91 | 91 | ||
92 | fn validate_func(&mut self, func: FunctionId) { | 92 | fn validate_func(&mut self, func: FunctionId) { |
93 | let data = self.db.function_data(func); | 93 | let data = self.db.function_data(func); |
94 | if data.is_extern { | 94 | if data.is_in_extern_block { |
95 | cov_mark::hit!(extern_func_incorrect_case_ignored); | 95 | cov_mark::hit!(extern_func_incorrect_case_ignored); |
96 | return; | 96 | return; |
97 | } | 97 | } |
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 20bb64827..44a7e5506 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -32,7 +32,7 @@ impl<'a, 'b> UnsafeValidator<'a, 'b> { | |||
32 | let def = self.owner.into(); | 32 | let def = self.owner.into(); |
33 | let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def); | 33 | let unsafe_expressions = unsafe_expressions(db, self.infer.as_ref(), def); |
34 | let is_unsafe = match self.owner { | 34 | let is_unsafe = match self.owner { |
35 | DefWithBodyId::FunctionId(it) => db.function_data(it).is_unsafe, | 35 | DefWithBodyId::FunctionId(it) => db.function_data(it).qualifier.is_unsafe, |
36 | DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) => false, | 36 | DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) => false, |
37 | }; | 37 | }; |
38 | if is_unsafe | 38 | if is_unsafe |
@@ -86,7 +86,7 @@ fn walk_unsafe( | |||
86 | match expr { | 86 | match expr { |
87 | &Expr::Call { callee, .. } => { | 87 | &Expr::Call { callee, .. } => { |
88 | if let Some(func) = infer[callee].as_fn_def(db) { | 88 | if let Some(func) = infer[callee].as_fn_def(db) { |
89 | if db.function_data(func).is_unsafe { | 89 | if db.function_data(func).qualifier.is_unsafe { |
90 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); | 90 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); |
91 | } | 91 | } |
92 | } | 92 | } |
@@ -103,7 +103,7 @@ fn walk_unsafe( | |||
103 | Expr::MethodCall { .. } => { | 103 | Expr::MethodCall { .. } => { |
104 | if infer | 104 | if infer |
105 | .method_resolution(current) | 105 | .method_resolution(current) |
106 | .map(|func| db.function_data(func).is_unsafe) | 106 | .map(|func| db.function_data(func).qualifier.is_unsafe) |
107 | .unwrap_or(false) | 107 | .unwrap_or(false) |
108 | { | 108 | { |
109 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); | 109 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index c1062387e..7ce0f864c 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -5,7 +5,13 @@ use std::{borrow::Cow, fmt}; | |||
5 | use arrayvec::ArrayVec; | 5 | use arrayvec::ArrayVec; |
6 | use chalk_ir::Mutability; | 6 | use chalk_ir::Mutability; |
7 | use hir_def::{ | 7 | use hir_def::{ |
8 | db::DefDatabase, find_path, generics::TypeParamProvenance, item_scope::ItemInNs, | 8 | db::DefDatabase, |
9 | find_path, | ||
10 | generics::TypeParamProvenance, | ||
11 | item_scope::ItemInNs, | ||
12 | path::{GenericArg, Path, PathKind}, | ||
13 | type_ref::{TypeBound, TypeRef}, | ||
14 | visibility::Visibility, | ||
9 | AssocContainerId, Lookup, ModuleId, TraitId, | 15 | AssocContainerId, Lookup, ModuleId, TraitId, |
10 | }; | 16 | }; |
11 | use hir_expand::name::Name; | 17 | use hir_expand::name::Name; |
@@ -14,7 +20,7 @@ use crate::{ | |||
14 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, | 20 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, |
15 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, | 21 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, |
16 | CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, | 22 | CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, |
17 | ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, | 23 | ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, |
18 | }; | 24 | }; |
19 | 25 | ||
20 | pub struct HirFormatter<'a> { | 26 | pub struct HirFormatter<'a> { |
@@ -232,7 +238,7 @@ where | |||
232 | 238 | ||
233 | const TYPE_HINT_TRUNCATION: &str = "…"; | 239 | const TYPE_HINT_TRUNCATION: &str = "…"; |
234 | 240 | ||
235 | impl HirDisplay for &Ty { | 241 | impl<T: HirDisplay> HirDisplay for &'_ T { |
236 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 242 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
237 | HirDisplay::hir_fmt(*self, f) | 243 | HirDisplay::hir_fmt(*self, f) |
238 | } | 244 | } |
@@ -556,7 +562,7 @@ impl HirDisplay for Ty { | |||
556 | } | 562 | } |
557 | TypeParamProvenance::ArgumentImplTrait => { | 563 | TypeParamProvenance::ArgumentImplTrait => { |
558 | let bounds = f.db.generic_predicates_for_param(id); | 564 | let bounds = f.db.generic_predicates_for_param(id); |
559 | let substs = Substs::type_params_for_generics(f.db, &generics); | 565 | let substs = Substitution::type_params_for_generics(f.db, &generics); |
560 | write_bounds_like_dyn_trait_with_prefix( | 566 | write_bounds_like_dyn_trait_with_prefix( |
561 | "impl", | 567 | "impl", |
562 | &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), | 568 | &bounds.iter().map(|b| b.clone().subst(&substs)).collect::<Vec<_>>(), |
@@ -761,12 +767,6 @@ impl HirDisplay for TraitRef { | |||
761 | } | 767 | } |
762 | } | 768 | } |
763 | 769 | ||
764 | impl HirDisplay for &GenericPredicate { | ||
765 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
766 | HirDisplay::hir_fmt(*self, f) | ||
767 | } | ||
768 | } | ||
769 | |||
770 | impl HirDisplay for GenericPredicate { | 770 | impl HirDisplay for GenericPredicate { |
771 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 771 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
772 | if f.should_truncate() { | 772 | if f.should_truncate() { |
@@ -825,3 +825,190 @@ impl HirDisplay for Obligation { | |||
825 | } | 825 | } |
826 | } | 826 | } |
827 | } | 827 | } |
828 | |||
829 | pub fn write_visibility( | ||
830 | module_id: ModuleId, | ||
831 | vis: Visibility, | ||
832 | f: &mut HirFormatter, | ||
833 | ) -> Result<(), HirDisplayError> { | ||
834 | match vis { | ||
835 | Visibility::Public => write!(f, "pub "), | ||
836 | Visibility::Module(vis_id) => { | ||
837 | let def_map = module_id.def_map(f.db.upcast()); | ||
838 | let root_module_id = def_map.module_id(def_map.root()); | ||
839 | if vis_id == module_id { | ||
840 | // pub(self) or omitted | ||
841 | Ok(()) | ||
842 | } else if root_module_id == vis_id { | ||
843 | write!(f, "pub(crate) ") | ||
844 | } else if module_id.containing_module(f.db.upcast()) == Some(vis_id) { | ||
845 | write!(f, "pub(super) ") | ||
846 | } else { | ||
847 | write!(f, "pub(in ...) ") | ||
848 | } | ||
849 | } | ||
850 | } | ||
851 | } | ||
852 | |||
853 | impl HirDisplay for TypeRef { | ||
854 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
855 | match self { | ||
856 | TypeRef::Never => write!(f, "!")?, | ||
857 | TypeRef::Placeholder => write!(f, "_")?, | ||
858 | TypeRef::Tuple(elems) => { | ||
859 | write!(f, "(")?; | ||
860 | f.write_joined(elems, ", ")?; | ||
861 | if elems.len() == 1 { | ||
862 | write!(f, ",")?; | ||
863 | } | ||
864 | write!(f, ")")?; | ||
865 | } | ||
866 | TypeRef::Path(path) => path.hir_fmt(f)?, | ||
867 | TypeRef::RawPtr(inner, mutability) => { | ||
868 | let mutability = match mutability { | ||
869 | hir_def::type_ref::Mutability::Shared => "*const ", | ||
870 | hir_def::type_ref::Mutability::Mut => "*mut ", | ||
871 | }; | ||
872 | write!(f, "{}", mutability)?; | ||
873 | inner.hir_fmt(f)?; | ||
874 | } | ||
875 | TypeRef::Reference(inner, lifetime, mutability) => { | ||
876 | let mutability = match mutability { | ||
877 | hir_def::type_ref::Mutability::Shared => "", | ||
878 | hir_def::type_ref::Mutability::Mut => "mut ", | ||
879 | }; | ||
880 | write!(f, "&")?; | ||
881 | if let Some(lifetime) = lifetime { | ||
882 | write!(f, "{} ", lifetime.name)?; | ||
883 | } | ||
884 | write!(f, "{}", mutability)?; | ||
885 | inner.hir_fmt(f)?; | ||
886 | } | ||
887 | TypeRef::Array(inner) => { | ||
888 | write!(f, "[")?; | ||
889 | inner.hir_fmt(f)?; | ||
890 | // FIXME: Array length? | ||
891 | write!(f, "; _]")?; | ||
892 | } | ||
893 | TypeRef::Slice(inner) => { | ||
894 | write!(f, "[")?; | ||
895 | inner.hir_fmt(f)?; | ||
896 | write!(f, "]")?; | ||
897 | } | ||
898 | TypeRef::Fn(tys, is_varargs) => { | ||
899 | // FIXME: Function pointer qualifiers. | ||
900 | write!(f, "fn(")?; | ||
901 | f.write_joined(&tys[..tys.len() - 1], ", ")?; | ||
902 | if *is_varargs { | ||
903 | write!(f, "{}...", if tys.len() == 1 { "" } else { ", " })?; | ||
904 | } | ||
905 | write!(f, ")")?; | ||
906 | let ret_ty = tys.last().unwrap(); | ||
907 | match ret_ty { | ||
908 | TypeRef::Tuple(tup) if tup.is_empty() => {} | ||
909 | _ => { | ||
910 | write!(f, " -> ")?; | ||
911 | ret_ty.hir_fmt(f)?; | ||
912 | } | ||
913 | } | ||
914 | } | ||
915 | TypeRef::ImplTrait(bounds) => { | ||
916 | write!(f, "impl ")?; | ||
917 | f.write_joined(bounds, " + ")?; | ||
918 | } | ||
919 | TypeRef::DynTrait(bounds) => { | ||
920 | write!(f, "dyn ")?; | ||
921 | f.write_joined(bounds, " + ")?; | ||
922 | } | ||
923 | TypeRef::Error => write!(f, "{{error}}")?, | ||
924 | } | ||
925 | Ok(()) | ||
926 | } | ||
927 | } | ||
928 | |||
929 | impl HirDisplay for TypeBound { | ||
930 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
931 | match self { | ||
932 | TypeBound::Path(path) => path.hir_fmt(f), | ||
933 | TypeBound::Lifetime(lifetime) => write!(f, "{}", lifetime.name), | ||
934 | TypeBound::Error => write!(f, "{{error}}"), | ||
935 | } | ||
936 | } | ||
937 | } | ||
938 | |||
939 | impl HirDisplay for Path { | ||
940 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
941 | match (self.type_anchor(), self.kind()) { | ||
942 | (Some(anchor), _) => { | ||
943 | write!(f, "<")?; | ||
944 | anchor.hir_fmt(f)?; | ||
945 | write!(f, ">")?; | ||
946 | } | ||
947 | (_, PathKind::Plain) => {} | ||
948 | (_, PathKind::Abs) => write!(f, "::")?, | ||
949 | (_, PathKind::Crate) => write!(f, "crate")?, | ||
950 | (_, PathKind::Super(0)) => write!(f, "self")?, | ||
951 | (_, PathKind::Super(n)) => { | ||
952 | write!(f, "super")?; | ||
953 | for _ in 0..*n { | ||
954 | write!(f, "::super")?; | ||
955 | } | ||
956 | } | ||
957 | (_, PathKind::DollarCrate(_)) => write!(f, "{{extern_crate}}")?, | ||
958 | } | ||
959 | |||
960 | for (seg_idx, segment) in self.segments().iter().enumerate() { | ||
961 | if seg_idx != 0 { | ||
962 | write!(f, "::")?; | ||
963 | } | ||
964 | write!(f, "{}", segment.name)?; | ||
965 | if let Some(generic_args) = segment.args_and_bindings { | ||
966 | // We should be in type context, so format as `Foo<Bar>` instead of `Foo::<Bar>`. | ||
967 | // Do we actually format expressions? | ||
968 | write!(f, "<")?; | ||
969 | let mut first = true; | ||
970 | for arg in &generic_args.args { | ||
971 | if first { | ||
972 | first = false; | ||
973 | if generic_args.has_self_type { | ||
974 | // FIXME: Convert to `<Ty as Trait>` form. | ||
975 | write!(f, "Self = ")?; | ||
976 | } | ||
977 | } else { | ||
978 | write!(f, ", ")?; | ||
979 | } | ||
980 | arg.hir_fmt(f)?; | ||
981 | } | ||
982 | for binding in &generic_args.bindings { | ||
983 | if first { | ||
984 | first = false; | ||
985 | } else { | ||
986 | write!(f, ", ")?; | ||
987 | } | ||
988 | write!(f, "{}", binding.name)?; | ||
989 | match &binding.type_ref { | ||
990 | Some(ty) => { | ||
991 | write!(f, " = ")?; | ||
992 | ty.hir_fmt(f)? | ||
993 | } | ||
994 | None => { | ||
995 | write!(f, ": ")?; | ||
996 | f.write_joined(&binding.bounds, " + ")?; | ||
997 | } | ||
998 | } | ||
999 | } | ||
1000 | write!(f, ">")?; | ||
1001 | } | ||
1002 | } | ||
1003 | Ok(()) | ||
1004 | } | ||
1005 | } | ||
1006 | |||
1007 | impl HirDisplay for GenericArg { | ||
1008 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
1009 | match self { | ||
1010 | GenericArg::Type(ty) => ty.hir_fmt(f), | ||
1011 | GenericArg::Lifetime(lifetime) => write!(f, "{}", lifetime.name), | ||
1012 | } | ||
1013 | } | ||
1014 | } | ||
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; | |||
38 | 38 | ||
39 | use super::{ | 39 | use super::{ |
40 | traits::{Guidance, Obligation, ProjectionPredicate, Solution}, | 40 | traits::{Guidance, Obligation, ProjectionPredicate, Solution}, |
41 | InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, | 41 | InEnvironment, ProjectionTy, Substitution, TraitEnvironment, TraitRef, Ty, TypeWalk, |
42 | }; | 42 | }; |
43 | use crate::{ | 43 | use crate::{ |
44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, | 44 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, |
@@ -390,7 +390,7 @@ impl<'a> InferenceContext<'a> { | |||
390 | _ => panic!("resolve_associated_type called with non-associated type"), | 390 | _ => panic!("resolve_associated_type called with non-associated type"), |
391 | }; | 391 | }; |
392 | let ty = self.table.new_type_var(); | 392 | let ty = self.table.new_type_var(); |
393 | let substs = Substs::build_for_def(self.db, res_assoc_ty) | 393 | let substs = Substitution::build_for_def(self.db, res_assoc_ty) |
394 | .push(inner_ty) | 394 | .push(inner_ty) |
395 | .fill(params.iter().cloned()) | 395 | .fill(params.iter().cloned()) |
396 | .build(); | 396 | .build(); |
@@ -469,7 +469,7 @@ impl<'a> InferenceContext<'a> { | |||
469 | } | 469 | } |
470 | TypeNs::SelfType(impl_id) => { | 470 | TypeNs::SelfType(impl_id) => { |
471 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); | 471 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
472 | let substs = Substs::type_params_for_generics(self.db, &generics); | 472 | let substs = Substitution::type_params_for_generics(self.db, &generics); |
473 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 473 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
474 | match unresolved { | 474 | match unresolved { |
475 | None => { | 475 | None => { |
@@ -496,7 +496,7 @@ impl<'a> InferenceContext<'a> { | |||
496 | } | 496 | } |
497 | } | 497 | } |
498 | TypeNs::TypeAliasId(it) => { | 498 | TypeNs::TypeAliasId(it) => { |
499 | let substs = Substs::build_for_def(self.db, it) | 499 | let substs = Substitution::build_for_def(self.db, it) |
500 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) | 500 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) |
501 | .build(); | 501 | .build(); |
502 | let ty = self.db.ty(it.into()).subst(&substs); | 502 | 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 @@ | |||
7 | use chalk_ir::{Mutability, TyVariableKind}; | 7 | use chalk_ir::{Mutability, TyVariableKind}; |
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{autoderef, traits::Solution, Interner, Obligation, Substs, TraitRef, Ty, TyKind}; | 10 | use crate::{ |
11 | autoderef, traits::Solution, Interner, Obligation, Substitution, TraitRef, Ty, TyKind, | ||
12 | }; | ||
11 | 13 | ||
12 | use super::{InEnvironment, InferenceContext}; | 14 | use super::{InEnvironment, InferenceContext}; |
13 | 15 | ||
@@ -134,7 +136,7 @@ impl<'a> InferenceContext<'a> { | |||
134 | return None; | 136 | return None; |
135 | } | 137 | } |
136 | 138 | ||
137 | let substs = Substs::build_for_generics(&generic_params) | 139 | let substs = Substitution::build_for_generics(&generic_params) |
138 | .push(from_ty.clone()) | 140 | .push(from_ty.clone()) |
139 | .push(to_ty.clone()) | 141 | .push(to_ty.clone()) |
140 | .build(); | 142 | .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::{ | |||
21 | to_assoc_type_id, | 21 | to_assoc_type_id, |
22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, | 22 | traits::{chalk::from_chalk, FnTrait, InEnvironment}, |
23 | utils::{generics, variant_data, Generics}, | 23 | utils::{generics, variant_data, Generics}, |
24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, Substs, | 24 | AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Obligation, Rawness, Scalar, |
25 | TraitRef, Ty, TyKind, | 25 | Substitution, TraitRef, Ty, TyKind, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | use super::{ | 28 | use super::{ |
@@ -77,7 +77,7 @@ impl<'a> InferenceContext<'a> { | |||
77 | return None; | 77 | return None; |
78 | } | 78 | } |
79 | 79 | ||
80 | let mut param_builder = Substs::builder(num_args); | 80 | let mut param_builder = Substitution::builder(num_args); |
81 | let mut arg_tys = vec![]; | 81 | let mut arg_tys = vec![]; |
82 | for _ in 0..num_args { | 82 | for _ in 0..num_args { |
83 | let arg = self.table.new_type_var(); | 83 | let arg = self.table.new_type_var(); |
@@ -87,7 +87,7 @@ impl<'a> InferenceContext<'a> { | |||
87 | let parameters = param_builder.build(); | 87 | let parameters = param_builder.build(); |
88 | let arg_ty = TyKind::Tuple(num_args, parameters).intern(&Interner); | 88 | let arg_ty = TyKind::Tuple(num_args, parameters).intern(&Interner); |
89 | let substs = | 89 | let substs = |
90 | Substs::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); | 90 | Substitution::build_for_generics(&generic_params).push(ty.clone()).push(arg_ty).build(); |
91 | 91 | ||
92 | let trait_env = Arc::clone(&self.trait_env); | 92 | let trait_env = Arc::clone(&self.trait_env); |
93 | let implements_fn_trait = | 93 | let implements_fn_trait = |
@@ -181,7 +181,7 @@ impl<'a> InferenceContext<'a> { | |||
181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); | 181 | let inner_ty = self.infer_expr(*body, &Expectation::none()); |
182 | let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body); | 182 | let impl_trait_id = crate::ImplTraitId::AsyncBlockTypeImplTrait(self.owner, *body); |
183 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); | 183 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); |
184 | TyKind::OpaqueType(opaque_ty_id, Substs::single(inner_ty)).intern(&Interner) | 184 | TyKind::OpaqueType(opaque_ty_id, Substitution::single(inner_ty)).intern(&Interner) |
185 | } | 185 | } |
186 | Expr::Loop { body, label } => { | 186 | Expr::Loop { body, label } => { |
187 | self.breakables.push(BreakableContext { | 187 | self.breakables.push(BreakableContext { |
@@ -262,12 +262,12 @@ impl<'a> InferenceContext<'a> { | |||
262 | let sig_ty = TyKind::Function(FnPointer { | 262 | let sig_ty = TyKind::Function(FnPointer { |
263 | num_args: sig_tys.len() - 1, | 263 | num_args: sig_tys.len() - 1, |
264 | sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false }, | 264 | sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false }, |
265 | substs: Substs(sig_tys.clone().into()), | 265 | substs: Substitution(sig_tys.clone().into()), |
266 | }) | 266 | }) |
267 | .intern(&Interner); | 267 | .intern(&Interner); |
268 | 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(); |
269 | let closure_ty = | 269 | let closure_ty = |
270 | TyKind::Closure(closure_id, Substs::single(sig_ty)).intern(&Interner); | 270 | TyKind::Closure(closure_id, Substitution::single(sig_ty)).intern(&Interner); |
271 | 271 | ||
272 | // Eagerly try to relate the closure type with the expected | 272 | // Eagerly try to relate the closure type with the expected |
273 | // type, otherwise we often won't have enough information to | 273 | // type, otherwise we often won't have enough information to |
@@ -402,7 +402,7 @@ impl<'a> InferenceContext<'a> { | |||
402 | 402 | ||
403 | self.unify(&ty, &expected.ty); | 403 | self.unify(&ty, &expected.ty); |
404 | 404 | ||
405 | let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); | 405 | let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); |
406 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); | 406 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); |
407 | let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); | 407 | let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); |
408 | for field in fields.iter() { | 408 | for field in fields.iter() { |
@@ -511,7 +511,8 @@ impl<'a> InferenceContext<'a> { | |||
511 | Expr::Box { expr } => { | 511 | Expr::Box { expr } => { |
512 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); | 512 | let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); |
513 | if let Some(box_) = self.resolve_boxed_box() { | 513 | if let Some(box_) = self.resolve_boxed_box() { |
514 | let mut sb = Substs::builder(generics(self.db.upcast(), box_.into()).len()); | 514 | let mut sb = |
515 | Substitution::builder(generics(self.db.upcast(), box_.into()).len()); | ||
515 | sb = sb.push(inner_ty); | 516 | sb = sb.push(inner_ty); |
516 | match self.db.generic_defaults(box_.into()).as_ref() { | 517 | match self.db.generic_defaults(box_.into()).as_ref() { |
517 | [_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => { | 518 | [_, alloc_ty, ..] if !alloc_ty.value.is_unknown() => { |
@@ -610,31 +611,31 @@ impl<'a> InferenceContext<'a> { | |||
610 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); | 611 | let rhs_ty = rhs.map(|e| self.infer_expr(e, &rhs_expect)); |
611 | match (range_type, lhs_ty, rhs_ty) { | 612 | match (range_type, lhs_ty, rhs_ty) { |
612 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { | 613 | (RangeOp::Exclusive, None, None) => match self.resolve_range_full() { |
613 | Some(adt) => Ty::adt_ty(adt, Substs::empty()), | 614 | Some(adt) => Ty::adt_ty(adt, Substitution::empty()), |
614 | None => self.err_ty(), | 615 | None => self.err_ty(), |
615 | }, | 616 | }, |
616 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { | 617 | (RangeOp::Exclusive, None, Some(ty)) => match self.resolve_range_to() { |
617 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), | 618 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), |
618 | None => self.err_ty(), | 619 | None => self.err_ty(), |
619 | }, | 620 | }, |
620 | (RangeOp::Inclusive, None, Some(ty)) => { | 621 | (RangeOp::Inclusive, None, Some(ty)) => { |
621 | match self.resolve_range_to_inclusive() { | 622 | match self.resolve_range_to_inclusive() { |
622 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), | 623 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), |
623 | None => self.err_ty(), | 624 | None => self.err_ty(), |
624 | } | 625 | } |
625 | } | 626 | } |
626 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { | 627 | (RangeOp::Exclusive, Some(_), Some(ty)) => match self.resolve_range() { |
627 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), | 628 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), |
628 | None => self.err_ty(), | 629 | None => self.err_ty(), |
629 | }, | 630 | }, |
630 | (RangeOp::Inclusive, Some(_), Some(ty)) => { | 631 | (RangeOp::Inclusive, Some(_), Some(ty)) => { |
631 | match self.resolve_range_inclusive() { | 632 | match self.resolve_range_inclusive() { |
632 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), | 633 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), |
633 | None => self.err_ty(), | 634 | None => self.err_ty(), |
634 | } | 635 | } |
635 | } | 636 | } |
636 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { | 637 | (RangeOp::Exclusive, Some(ty), None) => match self.resolve_range_from() { |
637 | Some(adt) => Ty::adt_ty(adt, Substs::single(ty)), | 638 | Some(adt) => Ty::adt_ty(adt, Substitution::single(ty)), |
638 | None => self.err_ty(), | 639 | None => self.err_ty(), |
639 | }, | 640 | }, |
640 | (RangeOp::Inclusive, _, None) => self.err_ty(), | 641 | (RangeOp::Inclusive, _, None) => self.err_ty(), |
@@ -681,7 +682,7 @@ impl<'a> InferenceContext<'a> { | |||
681 | self.infer_expr_coerce(*expr, &Expectation::has_type(ty.clone())); | 682 | self.infer_expr_coerce(*expr, &Expectation::has_type(ty.clone())); |
682 | } | 683 | } |
683 | 684 | ||
684 | TyKind::Tuple(tys.len(), Substs(tys.into())).intern(&Interner) | 685 | TyKind::Tuple(tys.len(), Substitution(tys.into())).intern(&Interner) |
685 | } | 686 | } |
686 | Expr::Array(array) => { | 687 | Expr::Array(array) => { |
687 | let elem_ty = match expected.ty.interned(&Interner) { | 688 | let elem_ty = match expected.ty.interned(&Interner) { |
@@ -887,7 +888,7 @@ impl<'a> InferenceContext<'a> { | |||
887 | def_generics: Option<Generics>, | 888 | def_generics: Option<Generics>, |
888 | generic_args: Option<&GenericArgs>, | 889 | generic_args: Option<&GenericArgs>, |
889 | receiver_ty: &Ty, | 890 | receiver_ty: &Ty, |
890 | ) -> Substs { | 891 | ) -> Substitution { |
891 | let (parent_params, self_params, type_params, impl_trait_params) = | 892 | let (parent_params, self_params, type_params, impl_trait_params) = |
892 | def_generics.as_ref().map_or((0, 0, 0, 0), |g| g.provenance_split()); | 893 | def_generics.as_ref().map_or((0, 0, 0, 0), |g| g.provenance_split()); |
893 | assert_eq!(self_params, 0); // method shouldn't have another Self param | 894 | assert_eq!(self_params, 0); // method shouldn't have another Self param |
@@ -926,7 +927,7 @@ impl<'a> InferenceContext<'a> { | |||
926 | substs.push(self.err_ty()); | 927 | substs.push(self.err_ty()); |
927 | } | 928 | } |
928 | assert_eq!(substs.len(), total_len); | 929 | assert_eq!(substs.len(), total_len); |
929 | Substs(substs.into()) | 930 | Substitution(substs.into()) |
930 | } | 931 | } |
931 | 932 | ||
932 | fn register_obligations_for_call(&mut self, callable_ty: &Ty) { | 933 | 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::{ | |||
12 | use hir_expand::name::Name; | 12 | use hir_expand::name::Name; |
13 | 13 | ||
14 | use super::{BindingMode, Expectation, InferenceContext}; | 14 | use super::{BindingMode, Expectation, InferenceContext}; |
15 | use crate::{lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substs, Ty, TyKind}; | 15 | use crate::{ |
16 | lower::lower_to_chalk_mutability, utils::variant_data, Interner, Substitution, Ty, TyKind, | ||
17 | }; | ||
16 | 18 | ||
17 | impl<'a> InferenceContext<'a> { | 19 | impl<'a> InferenceContext<'a> { |
18 | fn infer_tuple_struct_pat( | 20 | fn infer_tuple_struct_pat( |
@@ -31,7 +33,7 @@ impl<'a> InferenceContext<'a> { | |||
31 | } | 33 | } |
32 | self.unify(&ty, expected); | 34 | self.unify(&ty, expected); |
33 | 35 | ||
34 | let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); | 36 | let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); |
35 | 37 | ||
36 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); | 38 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
37 | let (pre, post) = match ellipsis { | 39 | let (pre, post) = match ellipsis { |
@@ -70,7 +72,7 @@ impl<'a> InferenceContext<'a> { | |||
70 | 72 | ||
71 | self.unify(&ty, expected); | 73 | self.unify(&ty, expected); |
72 | 74 | ||
73 | let substs = ty.substs().cloned().unwrap_or_else(Substs::empty); | 75 | let substs = ty.substs().cloned().unwrap_or_else(Substitution::empty); |
74 | 76 | ||
75 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); | 77 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
76 | for subpat in subpats { | 78 | for subpat in subpats { |
@@ -138,7 +140,7 @@ impl<'a> InferenceContext<'a> { | |||
138 | inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); | 140 | inner_tys.extend(expectations_iter.by_ref().take(n_uncovered_patterns).cloned()); |
139 | inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); | 141 | inner_tys.extend(post.iter().zip(expectations_iter).map(infer_pat)); |
140 | 142 | ||
141 | TyKind::Tuple(inner_tys.len(), Substs(inner_tys.into())).intern(&Interner) | 143 | TyKind::Tuple(inner_tys.len(), Substitution(inner_tys.into())).intern(&Interner) |
142 | } | 144 | } |
143 | Pat::Or(ref pats) => { | 145 | Pat::Or(ref pats) => { |
144 | if let Some((first_pat, rest)) = pats.split_first() { | 146 | if let Some((first_pat, rest)) = pats.split_first() { |
@@ -237,7 +239,7 @@ impl<'a> InferenceContext<'a> { | |||
237 | }; | 239 | }; |
238 | 240 | ||
239 | let inner_ty = self.infer_pat(*inner, &inner_expected, default_bm); | 241 | let inner_ty = self.infer_pat(*inner, &inner_expected, default_bm); |
240 | Ty::adt_ty(box_adt, Substs::single(inner_ty)) | 242 | Ty::adt_ty(box_adt, Substitution::single(inner_ty)) |
241 | } | 243 | } |
242 | None => self.err_ty(), | 244 | None => self.err_ty(), |
243 | }, | 245 | }, |
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::{ | |||
9 | }; | 9 | }; |
10 | use hir_expand::name::Name; | 10 | use hir_expand::name::Name; |
11 | 11 | ||
12 | use crate::{method_resolution, Interner, Substs, Ty, TyKind, ValueTyDefId}; | 12 | use crate::{method_resolution, Interner, Substitution, Ty, TyKind, ValueTyDefId}; |
13 | 13 | ||
14 | use super::{ExprOrPatId, InferenceContext, TraitRef}; | 14 | use super::{ExprOrPatId, InferenceContext, TraitRef}; |
15 | 15 | ||
@@ -79,7 +79,7 @@ impl<'a> InferenceContext<'a> { | |||
79 | } | 79 | } |
80 | ValueNs::ImplSelf(impl_id) => { | 80 | ValueNs::ImplSelf(impl_id) => { |
81 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); | 81 | let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); |
82 | let substs = Substs::type_params_for_generics(self.db, &generics); | 82 | let substs = Substitution::type_params_for_generics(self.db, &generics); |
83 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); | 83 | let ty = self.db.impl_self_ty(impl_id).subst(&substs); |
84 | if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { | 84 | if let Some((AdtId::StructId(struct_id), substs)) = ty.as_adt() { |
85 | let ty = self.db.value_ty(struct_id.into()).subst(&substs); | 85 | let ty = self.db.value_ty(struct_id.into()).subst(&substs); |
@@ -94,10 +94,10 @@ impl<'a> InferenceContext<'a> { | |||
94 | 94 | ||
95 | let ty = self.db.value_ty(typable); | 95 | let ty = self.db.value_ty(typable); |
96 | // self_subst is just for the parent | 96 | // self_subst is just for the parent |
97 | let parent_substs = self_subst.unwrap_or_else(Substs::empty); | 97 | let parent_substs = self_subst.unwrap_or_else(Substitution::empty); |
98 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); | 98 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
99 | let substs = ctx.substs_from_path(path, typable, true); | 99 | let substs = ctx.substs_from_path(path, typable, true); |
100 | let full_substs = Substs::builder(substs.len()) | 100 | let full_substs = Substitution::builder(substs.len()) |
101 | .use_parent_substs(&parent_substs) | 101 | .use_parent_substs(&parent_substs) |
102 | .fill(substs.0[parent_substs.len()..].iter().cloned()) | 102 | .fill(substs.0[parent_substs.len()..].iter().cloned()) |
103 | .build(); | 103 | .build(); |
@@ -111,7 +111,7 @@ impl<'a> InferenceContext<'a> { | |||
111 | path: &Path, | 111 | path: &Path, |
112 | remaining_index: usize, | 112 | remaining_index: usize, |
113 | id: ExprOrPatId, | 113 | id: ExprOrPatId, |
114 | ) -> Option<(ValueNs, Option<Substs>)> { | 114 | ) -> Option<(ValueNs, Option<Substitution>)> { |
115 | assert!(remaining_index < path.segments().len()); | 115 | assert!(remaining_index < path.segments().len()); |
116 | // there may be more intermediate segments between the resolved one and | 116 | // there may be more intermediate segments between the resolved one and |
117 | // the end. Only the last segment needs to be resolved to a value; from | 117 | // the end. Only the last segment needs to be resolved to a value; from |
@@ -164,7 +164,7 @@ impl<'a> InferenceContext<'a> { | |||
164 | trait_ref: TraitRef, | 164 | trait_ref: TraitRef, |
165 | segment: PathSegment<'_>, | 165 | segment: PathSegment<'_>, |
166 | id: ExprOrPatId, | 166 | id: ExprOrPatId, |
167 | ) -> Option<(ValueNs, Option<Substs>)> { | 167 | ) -> Option<(ValueNs, Option<Substitution>)> { |
168 | let trait_ = trait_ref.trait_; | 168 | let trait_ = trait_ref.trait_; |
169 | let item = | 169 | let item = |
170 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { | 170 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { |
@@ -208,7 +208,7 @@ impl<'a> InferenceContext<'a> { | |||
208 | ty: Ty, | 208 | ty: Ty, |
209 | name: &Name, | 209 | name: &Name, |
210 | id: ExprOrPatId, | 210 | id: ExprOrPatId, |
211 | ) -> Option<(ValueNs, Option<Substs>)> { | 211 | ) -> Option<(ValueNs, Option<Substitution>)> { |
212 | if let TyKind::Unknown = ty.interned(&Interner) { | 212 | if let TyKind::Unknown = ty.interned(&Interner) { |
213 | return None; | 213 | return None; |
214 | } | 214 | } |
@@ -241,7 +241,7 @@ impl<'a> InferenceContext<'a> { | |||
241 | }; | 241 | }; |
242 | let substs = match container { | 242 | let substs = match container { |
243 | AssocContainerId::ImplId(impl_id) => { | 243 | AssocContainerId::ImplId(impl_id) => { |
244 | let impl_substs = Substs::build_for_def(self.db, impl_id) | 244 | let impl_substs = Substitution::build_for_def(self.db, impl_id) |
245 | .fill(iter::repeat_with(|| self.table.new_type_var())) | 245 | .fill(iter::repeat_with(|| self.table.new_type_var())) |
246 | .build(); | 246 | .build(); |
247 | let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); | 247 | let impl_self_ty = self.db.impl_self_ty(impl_id).subst(&impl_substs); |
@@ -250,7 +250,7 @@ impl<'a> InferenceContext<'a> { | |||
250 | } | 250 | } |
251 | AssocContainerId::TraitId(trait_) => { | 251 | AssocContainerId::TraitId(trait_) => { |
252 | // we're picking this method | 252 | // we're picking this method |
253 | let trait_substs = Substs::build_for_def(self.db, trait_) | 253 | let trait_substs = Substitution::build_for_def(self.db, trait_) |
254 | .push(ty.clone()) | 254 | .push(ty.clone()) |
255 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) | 255 | .fill(std::iter::repeat_with(|| self.table.new_type_var())) |
256 | .build(); | 256 | .build(); |
@@ -274,7 +274,7 @@ impl<'a> InferenceContext<'a> { | |||
274 | ty: &Ty, | 274 | ty: &Ty, |
275 | name: &Name, | 275 | name: &Name, |
276 | id: ExprOrPatId, | 276 | id: ExprOrPatId, |
277 | ) -> Option<(ValueNs, Option<Substs>)> { | 277 | ) -> Option<(ValueNs, Option<Substitution>)> { |
278 | let (enum_id, subst) = match ty.as_adt() { | 278 | let (enum_id, subst) = match ty.as_adt() { |
279 | Some((AdtId::EnumId(e), subst)) => (e, subst), | 279 | Some((AdtId::EnumId(e), subst)) => (e, subst), |
280 | _ => return None, | 280 | _ => 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}; | |||
8 | use super::{InferenceContext, Obligation}; | 8 | use super::{InferenceContext, Obligation}; |
9 | use crate::{ | 9 | use crate::{ |
10 | BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, InEnvironment, InferenceVar, | 10 | BoundVar, Canonical, DebruijnIndex, FnPointer, GenericPredicate, InEnvironment, InferenceVar, |
11 | Interner, Scalar, Substs, Ty, TyKind, TypeWalk, | 11 | Interner, Scalar, Substitution, Ty, TyKind, TypeWalk, |
12 | }; | 12 | }; |
13 | 13 | ||
14 | impl<'a> InferenceContext<'a> { | 14 | impl<'a> InferenceContext<'a> { |
@@ -123,10 +123,10 @@ impl<T> Canonicalized<T> { | |||
123 | pub(super) fn apply_solution( | 123 | pub(super) fn apply_solution( |
124 | &self, | 124 | &self, |
125 | ctx: &mut InferenceContext<'_>, | 125 | ctx: &mut InferenceContext<'_>, |
126 | solution: Canonical<Substs>, | 126 | solution: Canonical<Substitution>, |
127 | ) { | 127 | ) { |
128 | // the solution may contain new variables, which we need to convert to new inference vars | 128 | // the solution may contain new variables, which we need to convert to new inference vars |
129 | let new_vars = Substs( | 129 | let new_vars = Substitution( |
130 | solution | 130 | solution |
131 | .kinds | 131 | .kinds |
132 | .iter() | 132 | .iter() |
@@ -147,9 +147,9 @@ impl<T> Canonicalized<T> { | |||
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { | 150 | pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substitution> { |
151 | let mut table = InferenceTable::new(); | 151 | let mut table = InferenceTable::new(); |
152 | let vars = Substs( | 152 | let vars = Substitution( |
153 | tys.kinds | 153 | tys.kinds |
154 | .iter() | 154 | .iter() |
155 | // we always use type vars here because we want everything to | 155 | // we always use type vars here because we want everything to |
@@ -173,7 +173,7 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { | |||
173 | } | 173 | } |
174 | } | 174 | } |
175 | Some( | 175 | Some( |
176 | Substs::builder(tys.kinds.len()) | 176 | Substitution::builder(tys.kinds.len()) |
177 | .fill(vars.iter().map(|v| table.resolve_ty_completely(v.clone()))) | 177 | .fill(vars.iter().map(|v| table.resolve_ty_completely(v.clone()))) |
178 | .build(), | 178 | .build(), |
179 | ) | 179 | ) |
@@ -264,8 +264,8 @@ impl InferenceTable { | |||
264 | 264 | ||
265 | pub(crate) fn unify_substs( | 265 | pub(crate) fn unify_substs( |
266 | &mut self, | 266 | &mut self, |
267 | substs1: &Substs, | 267 | substs1: &Substitution, |
268 | substs2: &Substs, | 268 | substs2: &Substitution, |
269 | depth: usize, | 269 | depth: usize, |
270 | ) -> bool { | 270 | ) -> bool { |
271 | substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) | 271 | 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 { | |||
67 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 67 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
68 | pub struct OpaqueTy { | 68 | pub struct OpaqueTy { |
69 | pub opaque_ty_id: OpaqueTyId, | 69 | pub opaque_ty_id: OpaqueTyId, |
70 | pub substitution: Substs, | 70 | pub substitution: Substitution, |
71 | } | 71 | } |
72 | 72 | ||
73 | /// A "projection" type corresponds to an (unnormalized) | 73 | /// A "projection" type corresponds to an (unnormalized) |
@@ -76,7 +76,7 @@ pub struct OpaqueTy { | |||
76 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 76 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
77 | pub struct ProjectionTy { | 77 | pub struct ProjectionTy { |
78 | pub associated_ty_id: AssocTypeId, | 78 | pub associated_ty_id: AssocTypeId, |
79 | pub substitution: Substs, | 79 | pub substitution: Substitution, |
80 | } | 80 | } |
81 | 81 | ||
82 | impl ProjectionTy { | 82 | impl ProjectionTy { |
@@ -112,7 +112,7 @@ pub type FnSig = chalk_ir::FnSig<Interner>; | |||
112 | pub struct FnPointer { | 112 | pub struct FnPointer { |
113 | pub num_args: usize, | 113 | pub num_args: usize, |
114 | pub sig: FnSig, | 114 | pub sig: FnSig, |
115 | pub substs: Substs, | 115 | pub substs: Substitution, |
116 | } | 116 | } |
117 | 117 | ||
118 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 118 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
@@ -137,19 +137,19 @@ pub enum AliasTy { | |||
137 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 137 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
138 | pub enum TyKind { | 138 | pub enum TyKind { |
139 | /// Structures, enumerations and unions. | 139 | /// Structures, enumerations and unions. |
140 | Adt(AdtId<Interner>, Substs), | 140 | Adt(AdtId<Interner>, Substitution), |
141 | 141 | ||
142 | /// Represents an associated item like `Iterator::Item`. This is used | 142 | /// Represents an associated item like `Iterator::Item`. This is used |
143 | /// when we have tried to normalize a projection like `T::Item` but | 143 | /// when we have tried to normalize a projection like `T::Item` but |
144 | /// couldn't find a better representation. In that case, we generate | 144 | /// couldn't find a better representation. In that case, we generate |
145 | /// an **application type** like `(Iterator::Item)<T>`. | 145 | /// an **application type** like `(Iterator::Item)<T>`. |
146 | AssociatedType(AssocTypeId, Substs), | 146 | AssociatedType(AssocTypeId, Substitution), |
147 | 147 | ||
148 | /// a scalar type like `bool` or `u32` | 148 | /// a scalar type like `bool` or `u32` |
149 | Scalar(Scalar), | 149 | Scalar(Scalar), |
150 | 150 | ||
151 | /// A tuple type. For example, `(i32, bool)`. | 151 | /// A tuple type. For example, `(i32, bool)`. |
152 | Tuple(usize, Substs), | 152 | Tuple(usize, Substitution), |
153 | 153 | ||
154 | /// An array with the given length. Written as `[T; n]`. | 154 | /// An array with the given length. Written as `[T; n]`. |
155 | Array(Ty), | 155 | Array(Ty), |
@@ -169,7 +169,7 @@ pub enum TyKind { | |||
169 | /// analogous to the `AssociatedType` type constructor. | 169 | /// analogous to the `AssociatedType` type constructor. |
170 | /// It is also used as the type of async block, with one type parameter | 170 | /// It is also used as the type of async block, with one type parameter |
171 | /// representing the Future::Output type. | 171 | /// representing the Future::Output type. |
172 | OpaqueType(OpaqueTyId, Substs), | 172 | OpaqueType(OpaqueTyId, Substitution), |
173 | 173 | ||
174 | /// The anonymous type of a function declaration/definition. Each | 174 | /// The anonymous type of a function declaration/definition. Each |
175 | /// function has a unique type, which is output (for a function | 175 | /// function has a unique type, which is output (for a function |
@@ -183,7 +183,7 @@ pub enum TyKind { | |||
183 | /// fn foo() -> i32 { 1 } | 183 | /// fn foo() -> i32 { 1 } |
184 | /// let bar = foo; // bar: fn() -> i32 {foo} | 184 | /// let bar = foo; // bar: fn() -> i32 {foo} |
185 | /// ``` | 185 | /// ``` |
186 | FnDef(FnDefId, Substs), | 186 | FnDef(FnDefId, Substitution), |
187 | 187 | ||
188 | /// The pointee of a string slice. Written as `str`. | 188 | /// The pointee of a string slice. Written as `str`. |
189 | Str, | 189 | Str, |
@@ -195,7 +195,7 @@ pub enum TyKind { | |||
195 | /// | 195 | /// |
196 | /// The closure signature is stored in a `FnPtr` type in the first type | 196 | /// The closure signature is stored in a `FnPtr` type in the first type |
197 | /// parameter. | 197 | /// parameter. |
198 | Closure(ClosureId, Substs), | 198 | Closure(ClosureId, Substitution), |
199 | 199 | ||
200 | /// Represents a foreign type declared in external blocks. | 200 | /// Represents a foreign type declared in external blocks. |
201 | ForeignType(ForeignDefId), | 201 | ForeignType(ForeignDefId), |
@@ -273,9 +273,9 @@ impl Ty { | |||
273 | 273 | ||
274 | /// A list of substitutions for generic parameters. | 274 | /// A list of substitutions for generic parameters. |
275 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | 275 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] |
276 | pub struct Substs(SmallVec<[Ty; 2]>); | 276 | pub struct Substitution(SmallVec<[Ty; 2]>); |
277 | 277 | ||
278 | impl TypeWalk for Substs { | 278 | impl TypeWalk for Substitution { |
279 | fn walk(&self, f: &mut impl FnMut(&Ty)) { | 279 | fn walk(&self, f: &mut impl FnMut(&Ty)) { |
280 | for t in self.0.iter() { | 280 | for t in self.0.iter() { |
281 | t.walk(f); | 281 | t.walk(f); |
@@ -293,29 +293,29 @@ impl TypeWalk for Substs { | |||
293 | } | 293 | } |
294 | } | 294 | } |
295 | 295 | ||
296 | impl Substs { | 296 | impl Substitution { |
297 | pub fn interned(&self, _: &Interner) -> &[Ty] { | 297 | pub fn interned(&self, _: &Interner) -> &[Ty] { |
298 | &self.0 | 298 | &self.0 |
299 | } | 299 | } |
300 | 300 | ||
301 | pub fn empty() -> Substs { | 301 | pub fn empty() -> Substitution { |
302 | Substs(SmallVec::new()) | 302 | Substitution(SmallVec::new()) |
303 | } | 303 | } |
304 | 304 | ||
305 | pub fn single(ty: Ty) -> Substs { | 305 | pub fn single(ty: Ty) -> Substitution { |
306 | Substs({ | 306 | Substitution({ |
307 | let mut v = SmallVec::new(); | 307 | let mut v = SmallVec::new(); |
308 | v.push(ty); | 308 | v.push(ty); |
309 | v | 309 | v |
310 | }) | 310 | }) |
311 | } | 311 | } |
312 | 312 | ||
313 | pub fn prefix(&self, n: usize) -> Substs { | 313 | pub fn prefix(&self, n: usize) -> Substitution { |
314 | Substs(self.0[..std::cmp::min(self.0.len(), n)].into()) | 314 | Substitution(self.0[..std::cmp::min(self.0.len(), n)].into()) |
315 | } | 315 | } |
316 | 316 | ||
317 | pub fn suffix(&self, n: usize) -> Substs { | 317 | pub fn suffix(&self, n: usize) -> Substitution { |
318 | Substs(self.0[self.0.len() - std::cmp::min(self.0.len(), n)..].into()) | 318 | Substitution(self.0[self.0.len() - std::cmp::min(self.0.len(), n)..].into()) |
319 | } | 319 | } |
320 | 320 | ||
321 | pub fn as_single(&self) -> &Ty { | 321 | pub fn as_single(&self) -> &Ty { |
@@ -326,15 +326,15 @@ impl Substs { | |||
326 | } | 326 | } |
327 | 327 | ||
328 | pub fn from_iter(_interner: &Interner, elements: impl IntoIterator<Item = Ty>) -> Self { | 328 | pub fn from_iter(_interner: &Interner, elements: impl IntoIterator<Item = Ty>) -> Self { |
329 | Substs(elements.into_iter().collect()) | 329 | Substitution(elements.into_iter().collect()) |
330 | } | 330 | } |
331 | 331 | ||
332 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 332 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
333 | pub(crate) fn type_params_for_generics( | 333 | pub(crate) fn type_params_for_generics( |
334 | db: &dyn HirDatabase, | 334 | db: &dyn HirDatabase, |
335 | generic_params: &Generics, | 335 | generic_params: &Generics, |
336 | ) -> Substs { | 336 | ) -> Substitution { |
337 | Substs( | 337 | Substitution( |
338 | generic_params | 338 | generic_params |
339 | .iter() | 339 | .iter() |
340 | .map(|(id, _)| TyKind::Placeholder(to_placeholder_idx(db, id)).intern(&Interner)) | 340 | .map(|(id, _)| TyKind::Placeholder(to_placeholder_idx(db, id)).intern(&Interner)) |
@@ -343,14 +343,14 @@ impl Substs { | |||
343 | } | 343 | } |
344 | 344 | ||
345 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). | 345 | /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). |
346 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substs { | 346 | pub fn type_params(db: &dyn HirDatabase, def: impl Into<GenericDefId>) -> Substitution { |
347 | let params = generics(db.upcast(), def.into()); | 347 | let params = generics(db.upcast(), def.into()); |
348 | Substs::type_params_for_generics(db, ¶ms) | 348 | Substitution::type_params_for_generics(db, ¶ms) |
349 | } | 349 | } |
350 | 350 | ||
351 | /// Return Substs that replace each parameter by a bound variable. | 351 | /// Return Substs that replace each parameter by a bound variable. |
352 | pub(crate) fn bound_vars(generic_params: &Generics, debruijn: DebruijnIndex) -> Substs { | 352 | pub(crate) fn bound_vars(generic_params: &Generics, debruijn: DebruijnIndex) -> Substitution { |
353 | Substs( | 353 | Substitution( |
354 | generic_params | 354 | generic_params |
355 | .iter() | 355 | .iter() |
356 | .enumerate() | 356 | .enumerate() |
@@ -363,11 +363,11 @@ impl Substs { | |||
363 | let def = def.into(); | 363 | let def = def.into(); |
364 | let params = generics(db.upcast(), def); | 364 | let params = generics(db.upcast(), def); |
365 | let param_count = params.len(); | 365 | let param_count = params.len(); |
366 | Substs::builder(param_count) | 366 | Substitution::builder(param_count) |
367 | } | 367 | } |
368 | 368 | ||
369 | pub(crate) fn build_for_generics(generic_params: &Generics) -> SubstsBuilder { | 369 | pub(crate) fn build_for_generics(generic_params: &Generics) -> SubstsBuilder { |
370 | Substs::builder(generic_params.len()) | 370 | Substitution::builder(generic_params.len()) |
371 | } | 371 | } |
372 | 372 | ||
373 | fn builder(param_count: usize) -> SubstsBuilder { | 373 | fn builder(param_count: usize) -> SubstsBuilder { |
@@ -387,9 +387,9 @@ pub struct SubstsBuilder { | |||
387 | } | 387 | } |
388 | 388 | ||
389 | impl SubstsBuilder { | 389 | impl SubstsBuilder { |
390 | pub fn build(self) -> Substs { | 390 | pub fn build(self) -> Substitution { |
391 | assert_eq!(self.vec.len(), self.param_count); | 391 | assert_eq!(self.vec.len(), self.param_count); |
392 | Substs(self.vec.into()) | 392 | Substitution(self.vec.into()) |
393 | } | 393 | } |
394 | 394 | ||
395 | pub fn push(mut self, ty: Ty) -> Self { | 395 | pub fn push(mut self, ty: Ty) -> Self { |
@@ -418,7 +418,7 @@ impl SubstsBuilder { | |||
418 | self | 418 | self |
419 | } | 419 | } |
420 | 420 | ||
421 | pub fn use_parent_substs(mut self, parent_substs: &Substs) -> Self { | 421 | pub fn use_parent_substs(mut self, parent_substs: &Substitution) -> Self { |
422 | assert!(self.vec.is_empty()); | 422 | assert!(self.vec.is_empty()); |
423 | assert!(parent_substs.len() <= self.param_count); | 423 | assert!(parent_substs.len() <= self.param_count); |
424 | self.vec.extend(parent_substs.iter().cloned()); | 424 | self.vec.extend(parent_substs.iter().cloned()); |
@@ -426,7 +426,7 @@ impl SubstsBuilder { | |||
426 | } | 426 | } |
427 | } | 427 | } |
428 | 428 | ||
429 | impl Deref for Substs { | 429 | impl Deref for Substitution { |
430 | type Target = [Ty]; | 430 | type Target = [Ty]; |
431 | 431 | ||
432 | fn deref(&self) -> &[Ty] { | 432 | fn deref(&self) -> &[Ty] { |
@@ -466,13 +466,13 @@ impl<T: Clone> Binders<&T> { | |||
466 | 466 | ||
467 | impl<T: TypeWalk> Binders<T> { | 467 | impl<T: TypeWalk> Binders<T> { |
468 | /// Substitutes all variables. | 468 | /// Substitutes all variables. |
469 | pub fn subst(self, subst: &Substs) -> T { | 469 | pub fn subst(self, subst: &Substitution) -> T { |
470 | assert_eq!(subst.len(), self.num_binders); | 470 | assert_eq!(subst.len(), self.num_binders); |
471 | self.value.subst_bound_vars(subst) | 471 | self.value.subst_bound_vars(subst) |
472 | } | 472 | } |
473 | 473 | ||
474 | /// Substitutes just a prefix of the variables (shifting the rest). | 474 | /// Substitutes just a prefix of the variables (shifting the rest). |
475 | pub fn subst_prefix(self, subst: &Substs) -> Binders<T> { | 475 | pub fn subst_prefix(self, subst: &Substitution) -> Binders<T> { |
476 | assert!(subst.len() < self.num_binders); | 476 | assert!(subst.len() < self.num_binders); |
477 | Binders::new(self.num_binders - subst.len(), self.value.subst_bound_vars(subst)) | 477 | Binders::new(self.num_binders - subst.len(), self.value.subst_bound_vars(subst)) |
478 | } | 478 | } |
@@ -498,7 +498,7 @@ impl<T: TypeWalk> TypeWalk for Binders<T> { | |||
498 | pub struct TraitRef { | 498 | pub struct TraitRef { |
499 | /// FIXME name? | 499 | /// FIXME name? |
500 | pub trait_: TraitId, | 500 | pub trait_: TraitId, |
501 | pub substs: Substs, | 501 | pub substs: Substitution, |
502 | } | 502 | } |
503 | 503 | ||
504 | impl TraitRef { | 504 | impl TraitRef { |
@@ -618,7 +618,7 @@ impl CallableSig { | |||
618 | } | 618 | } |
619 | } | 619 | } |
620 | 620 | ||
621 | pub fn from_substs(substs: &Substs) -> CallableSig { | 621 | pub fn from_substs(substs: &Substitution) -> CallableSig { |
622 | CallableSig { params_and_return: substs.iter().cloned().collect(), is_varargs: false } | 622 | CallableSig { params_and_return: substs.iter().cloned().collect(), is_varargs: false } |
623 | } | 623 | } |
624 | 624 | ||
@@ -651,10 +651,10 @@ impl TypeWalk for CallableSig { | |||
651 | 651 | ||
652 | impl Ty { | 652 | impl Ty { |
653 | pub fn unit() -> Self { | 653 | pub fn unit() -> Self { |
654 | TyKind::Tuple(0, Substs::empty()).intern(&Interner) | 654 | TyKind::Tuple(0, Substitution::empty()).intern(&Interner) |
655 | } | 655 | } |
656 | 656 | ||
657 | pub fn adt_ty(adt: hir_def::AdtId, substs: Substs) -> Ty { | 657 | pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty { |
658 | TyKind::Adt(AdtId(adt), substs).intern(&Interner) | 658 | TyKind::Adt(AdtId(adt), substs).intern(&Interner) |
659 | } | 659 | } |
660 | 660 | ||
@@ -662,7 +662,7 @@ impl Ty { | |||
662 | TyKind::Function(FnPointer { | 662 | TyKind::Function(FnPointer { |
663 | num_args: sig.params().len(), | 663 | num_args: sig.params().len(), |
664 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, | 664 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, |
665 | substs: Substs::from_iter(&Interner, sig.params_and_return.iter().cloned()), | 665 | substs: Substitution::from_iter(&Interner, sig.params_and_return.iter().cloned()), |
666 | }) | 666 | }) |
667 | .intern(&Interner) | 667 | .intern(&Interner) |
668 | } | 668 | } |
@@ -709,14 +709,14 @@ impl Ty { | |||
709 | t | 709 | t |
710 | } | 710 | } |
711 | 711 | ||
712 | pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substs)> { | 712 | pub fn as_adt(&self) -> Option<(hir_def::AdtId, &Substitution)> { |
713 | match self.interned(&Interner) { | 713 | match self.interned(&Interner) { |
714 | TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)), | 714 | TyKind::Adt(AdtId(adt), parameters) => Some((*adt, parameters)), |
715 | _ => None, | 715 | _ => None, |
716 | } | 716 | } |
717 | } | 717 | } |
718 | 718 | ||
719 | pub fn as_tuple(&self) -> Option<&Substs> { | 719 | pub fn as_tuple(&self) -> Option<&Substitution> { |
720 | match self.interned(&Interner) { | 720 | match self.interned(&Interner) { |
721 | TyKind::Tuple(_, substs) => Some(substs), | 721 | TyKind::Tuple(_, substs) => Some(substs), |
722 | _ => None, | 722 | _ => None, |
@@ -828,7 +828,7 @@ impl Ty { | |||
828 | 828 | ||
829 | /// Returns the type parameters of this type if it has some (i.e. is an ADT | 829 | /// Returns the type parameters of this type if it has some (i.e. is an ADT |
830 | /// or function); so if `self` is `Option<u32>`, this returns the `u32`. | 830 | /// or function); so if `self` is `Option<u32>`, this returns the `u32`. |
831 | pub fn substs(&self) -> Option<&Substs> { | 831 | pub fn substs(&self) -> Option<&Substitution> { |
832 | match self.interned(&Interner) { | 832 | match self.interned(&Interner) { |
833 | TyKind::Adt(_, substs) | 833 | TyKind::Adt(_, substs) |
834 | | TyKind::FnDef(_, substs) | 834 | | TyKind::FnDef(_, substs) |
@@ -841,7 +841,7 @@ impl Ty { | |||
841 | } | 841 | } |
842 | } | 842 | } |
843 | 843 | ||
844 | fn substs_mut(&mut self) -> Option<&mut Substs> { | 844 | fn substs_mut(&mut self) -> Option<&mut Substitution> { |
845 | match self.interned_mut() { | 845 | match self.interned_mut() { |
846 | TyKind::Adt(_, substs) | 846 | TyKind::Adt(_, substs) |
847 | | TyKind::FnDef(_, substs) | 847 | | TyKind::FnDef(_, substs) |
@@ -869,7 +869,7 @@ impl Ty { | |||
869 | // So just provide the Future trait. | 869 | // So just provide the Future trait. |
870 | let impl_bound = GenericPredicate::Implemented(TraitRef { | 870 | let impl_bound = GenericPredicate::Implemented(TraitRef { |
871 | trait_: future_trait, | 871 | trait_: future_trait, |
872 | substs: Substs::empty(), | 872 | substs: Substitution::empty(), |
873 | }); | 873 | }); |
874 | Some(vec![impl_bound]) | 874 | Some(vec![impl_bound]) |
875 | } else { | 875 | } else { |
@@ -992,7 +992,7 @@ pub trait TypeWalk { | |||
992 | } | 992 | } |
993 | 993 | ||
994 | /// Substitutes `TyKind::Bound` vars with the given substitution. | 994 | /// Substitutes `TyKind::Bound` vars with the given substitution. |
995 | fn subst_bound_vars(self, substs: &Substs) -> Self | 995 | fn subst_bound_vars(self, substs: &Substitution) -> Self |
996 | where | 996 | where |
997 | Self: Sized, | 997 | Self: Sized, |
998 | { | 998 | { |
@@ -1000,7 +1000,7 @@ pub trait TypeWalk { | |||
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | /// Substitutes `TyKind::Bound` vars with the given substitution. | 1002 | /// Substitutes `TyKind::Bound` vars with the given substitution. |
1003 | fn subst_bound_vars_at_depth(mut self, substs: &Substs, depth: DebruijnIndex) -> Self | 1003 | fn subst_bound_vars_at_depth(mut self, substs: &Substitution, depth: DebruijnIndex) -> Self |
1004 | where | 1004 | where |
1005 | Self: Sized, | 1005 | Self: Sized, |
1006 | { | 1006 | { |
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::{ | |||
35 | }, | 35 | }, |
36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, | 36 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
37 | ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 37 | ImplTraitId, OpaqueTy, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
38 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, | 38 | ReturnTypeImplTraits, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, |
39 | }; | 39 | }; |
40 | 40 | ||
41 | #[derive(Debug)] | 41 | #[derive(Debug)] |
@@ -151,7 +151,7 @@ impl<'a> TyLoweringContext<'a> { | |||
151 | TypeRef::Never => TyKind::Never.intern(&Interner), | 151 | TypeRef::Never => TyKind::Never.intern(&Interner), |
152 | TypeRef::Tuple(inner) => { | 152 | TypeRef::Tuple(inner) => { |
153 | let inner_tys = inner.iter().map(|tr| self.lower_ty(tr)); | 153 | let inner_tys = inner.iter().map(|tr| self.lower_ty(tr)); |
154 | TyKind::Tuple(inner_tys.len(), Substs::from_iter(&Interner, inner_tys)) | 154 | TyKind::Tuple(inner_tys.len(), Substitution::from_iter(&Interner, inner_tys)) |
155 | .intern(&Interner) | 155 | .intern(&Interner) |
156 | } | 156 | } |
157 | TypeRef::Path(path) => { | 157 | TypeRef::Path(path) => { |
@@ -177,7 +177,7 @@ impl<'a> TyLoweringContext<'a> { | |||
177 | } | 177 | } |
178 | TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), | 178 | TypeRef::Placeholder => TyKind::Unknown.intern(&Interner), |
179 | TypeRef::Fn(params, is_varargs) => { | 179 | TypeRef::Fn(params, is_varargs) => { |
180 | let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); | 180 | let substs = Substitution(params.iter().map(|tr| self.lower_ty(tr)).collect()); |
181 | TyKind::Function(FnPointer { | 181 | TyKind::Function(FnPointer { |
182 | num_args: substs.len() - 1, | 182 | num_args: substs.len() - 1, |
183 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, | 183 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, |
@@ -228,7 +228,7 @@ impl<'a> TyLoweringContext<'a> { | |||
228 | let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); | 228 | let impl_trait_id = ImplTraitId::ReturnTypeImplTrait(func, idx); |
229 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); | 229 | let opaque_ty_id = self.db.intern_impl_trait_id(impl_trait_id).into(); |
230 | let generics = generics(self.db.upcast(), func.into()); | 230 | let generics = generics(self.db.upcast(), func.into()); |
231 | let parameters = Substs::bound_vars(&generics, self.in_binders); | 231 | let parameters = Substitution::bound_vars(&generics, self.in_binders); |
232 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { | 232 | TyKind::Alias(AliasTy::Opaque(OpaqueTy { |
233 | opaque_ty_id, | 233 | opaque_ty_id, |
234 | substitution: parameters, | 234 | substitution: parameters, |
@@ -398,10 +398,10 @@ impl<'a> TyLoweringContext<'a> { | |||
398 | let generics = generics(self.db.upcast(), impl_id.into()); | 398 | let generics = generics(self.db.upcast(), impl_id.into()); |
399 | let substs = match self.type_param_mode { | 399 | let substs = match self.type_param_mode { |
400 | TypeParamLoweringMode::Placeholder => { | 400 | TypeParamLoweringMode::Placeholder => { |
401 | Substs::type_params_for_generics(self.db, &generics) | 401 | Substitution::type_params_for_generics(self.db, &generics) |
402 | } | 402 | } |
403 | TypeParamLoweringMode::Variable => { | 403 | TypeParamLoweringMode::Variable => { |
404 | Substs::bound_vars(&generics, self.in_binders) | 404 | Substitution::bound_vars(&generics, self.in_binders) |
405 | } | 405 | } |
406 | }; | 406 | }; |
407 | self.db.impl_self_ty(impl_id).subst(&substs) | 407 | self.db.impl_self_ty(impl_id).subst(&substs) |
@@ -410,10 +410,10 @@ impl<'a> TyLoweringContext<'a> { | |||
410 | let generics = generics(self.db.upcast(), adt.into()); | 410 | let generics = generics(self.db.upcast(), adt.into()); |
411 | let substs = match self.type_param_mode { | 411 | let substs = match self.type_param_mode { |
412 | TypeParamLoweringMode::Placeholder => { | 412 | TypeParamLoweringMode::Placeholder => { |
413 | Substs::type_params_for_generics(self.db, &generics) | 413 | Substitution::type_params_for_generics(self.db, &generics) |
414 | } | 414 | } |
415 | TypeParamLoweringMode::Variable => { | 415 | TypeParamLoweringMode::Variable => { |
416 | Substs::bound_vars(&generics, self.in_binders) | 416 | Substitution::bound_vars(&generics, self.in_binders) |
417 | } | 417 | } |
418 | }; | 418 | }; |
419 | self.db.ty(adt.into()).subst(&substs) | 419 | self.db.ty(adt.into()).subst(&substs) |
@@ -464,7 +464,7 @@ impl<'a> TyLoweringContext<'a> { | |||
464 | TypeParamLoweringMode::Placeholder => { | 464 | TypeParamLoweringMode::Placeholder => { |
465 | // if we're lowering to placeholders, we have to put | 465 | // if we're lowering to placeholders, we have to put |
466 | // them in now | 466 | // them in now |
467 | let s = Substs::type_params( | 467 | let s = Substitution::type_params( |
468 | self.db, | 468 | self.db, |
469 | self.resolver.generic_def().expect( | 469 | self.resolver.generic_def().expect( |
470 | "there should be generics if there's a generic param", | 470 | "there should be generics if there's a generic param", |
@@ -522,7 +522,7 @@ impl<'a> TyLoweringContext<'a> { | |||
522 | // special-case enum variants | 522 | // special-case enum variants |
523 | resolved: ValueTyDefId, | 523 | resolved: ValueTyDefId, |
524 | infer_args: bool, | 524 | infer_args: bool, |
525 | ) -> Substs { | 525 | ) -> Substitution { |
526 | let last = path.segments().last().expect("path should have at least one segment"); | 526 | let last = path.segments().last().expect("path should have at least one segment"); |
527 | let (segment, generic_def) = match resolved { | 527 | let (segment, generic_def) = match resolved { |
528 | ValueTyDefId::FunctionId(it) => (last, Some(it.into())), | 528 | ValueTyDefId::FunctionId(it) => (last, Some(it.into())), |
@@ -553,7 +553,7 @@ impl<'a> TyLoweringContext<'a> { | |||
553 | segment: PathSegment<'_>, | 553 | segment: PathSegment<'_>, |
554 | def_generic: Option<GenericDefId>, | 554 | def_generic: Option<GenericDefId>, |
555 | infer_args: bool, | 555 | infer_args: bool, |
556 | ) -> Substs { | 556 | ) -> Substitution { |
557 | let mut substs = Vec::new(); | 557 | let mut substs = Vec::new(); |
558 | let def_generics = def_generic.map(|def| generics(self.db.upcast(), def)); | 558 | let def_generics = def_generic.map(|def| generics(self.db.upcast(), def)); |
559 | 559 | ||
@@ -601,7 +601,7 @@ impl<'a> TyLoweringContext<'a> { | |||
601 | 601 | ||
602 | for default_ty in defaults.iter().skip(substs.len()) { | 602 | for default_ty in defaults.iter().skip(substs.len()) { |
603 | // each default can depend on the previous parameters | 603 | // each default can depend on the previous parameters |
604 | let substs_so_far = Substs(substs.clone().into()); | 604 | let substs_so_far = Substitution(substs.clone().into()); |
605 | substs.push(default_ty.clone().subst(&substs_so_far)); | 605 | substs.push(default_ty.clone().subst(&substs_so_far)); |
606 | } | 606 | } |
607 | } | 607 | } |
@@ -614,7 +614,7 @@ impl<'a> TyLoweringContext<'a> { | |||
614 | } | 614 | } |
615 | assert_eq!(substs.len(), total_len); | 615 | assert_eq!(substs.len(), total_len); |
616 | 616 | ||
617 | Substs(substs.into()) | 617 | Substitution(substs.into()) |
618 | } | 618 | } |
619 | 619 | ||
620 | fn lower_trait_ref_from_path( | 620 | fn lower_trait_ref_from_path( |
@@ -656,7 +656,11 @@ impl<'a> TyLoweringContext<'a> { | |||
656 | self.lower_trait_ref_from_path(path, explicit_self_ty) | 656 | self.lower_trait_ref_from_path(path, explicit_self_ty) |
657 | } | 657 | } |
658 | 658 | ||
659 | fn trait_ref_substs_from_path(&self, segment: PathSegment<'_>, resolved: TraitId) -> Substs { | 659 | fn trait_ref_substs_from_path( |
660 | &self, | ||
661 | segment: PathSegment<'_>, | ||
662 | resolved: TraitId, | ||
663 | ) -> Substitution { | ||
660 | self.substs_from_path_segment(segment, Some(resolved.into()), false) | 664 | self.substs_from_path_segment(segment, Some(resolved.into()), false) |
661 | } | 665 | } |
662 | 666 | ||
@@ -817,7 +821,7 @@ pub fn associated_type_shorthand_candidates<R>( | |||
817 | { | 821 | { |
818 | let trait_ref = TraitRef { | 822 | let trait_ref = TraitRef { |
819 | trait_: trait_id, | 823 | trait_: trait_id, |
820 | substs: Substs::bound_vars(&generics, DebruijnIndex::INNERMOST), | 824 | substs: Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST), |
821 | }; | 825 | }; |
822 | traits_.push(trait_ref); | 826 | traits_.push(trait_ref); |
823 | } | 827 | } |
@@ -945,7 +949,7 @@ pub(crate) fn trait_environment_query( | |||
945 | // function default implementations (and hypothetical code | 949 | // function default implementations (and hypothetical code |
946 | // inside consts or type aliases) | 950 | // inside consts or type aliases) |
947 | cov_mark::hit!(trait_self_implements_self); | 951 | cov_mark::hit!(trait_self_implements_self); |
948 | let substs = Substs::type_params(db, trait_id); | 952 | let substs = Substitution::type_params(db, trait_id); |
949 | let trait_ref = TraitRef { trait_: trait_id, substs }; | 953 | let trait_ref = TraitRef { trait_: trait_id, substs }; |
950 | let pred = GenericPredicate::Implemented(trait_ref); | 954 | let pred = GenericPredicate::Implemented(trait_ref); |
951 | let program_clause: chalk_ir::ProgramClause<Interner> = | 955 | let program_clause: chalk_ir::ProgramClause<Interner> = |
@@ -1033,7 +1037,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { | |||
1033 | /// function body. | 1037 | /// function body. |
1034 | fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { | 1038 | fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders<Ty> { |
1035 | let generics = generics(db.upcast(), def.into()); | 1039 | let generics = generics(db.upcast(), def.into()); |
1036 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1040 | let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1037 | Binders::new( | 1041 | Binders::new( |
1038 | substs.len(), | 1042 | substs.len(), |
1039 | TyKind::FnDef(CallableDefId::FunctionId(def).to_chalk(db), substs).intern(&Interner), | 1043 | 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<T | |||
1078 | return type_for_adt(db, def.into()); | 1082 | return type_for_adt(db, def.into()); |
1079 | } | 1083 | } |
1080 | let generics = generics(db.upcast(), def.into()); | 1084 | let generics = generics(db.upcast(), def.into()); |
1081 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1085 | let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1082 | Binders::new( | 1086 | Binders::new( |
1083 | substs.len(), | 1087 | substs.len(), |
1084 | TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner), | 1088 | TyKind::FnDef(CallableDefId::StructId(def).to_chalk(db), substs).intern(&Interner), |
@@ -1105,7 +1109,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) - | |||
1105 | return type_for_adt(db, def.parent.into()); | 1109 | return type_for_adt(db, def.parent.into()); |
1106 | } | 1110 | } |
1107 | let generics = generics(db.upcast(), def.parent.into()); | 1111 | let generics = generics(db.upcast(), def.parent.into()); |
1108 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1112 | let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1109 | Binders::new( | 1113 | Binders::new( |
1110 | substs.len(), | 1114 | substs.len(), |
1111 | TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner), | 1115 | TyKind::FnDef(CallableDefId::EnumVariantId(def).to_chalk(db), substs).intern(&Interner), |
@@ -1114,7 +1118,7 @@ fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) - | |||
1114 | 1118 | ||
1115 | fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { | 1119 | fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders<Ty> { |
1116 | let generics = generics(db.upcast(), adt.into()); | 1120 | let generics = generics(db.upcast(), adt.into()); |
1117 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1121 | let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1118 | Binders::new(substs.len(), Ty::adt_ty(adt, substs)) | 1122 | Binders::new(substs.len(), Ty::adt_ty(adt, substs)) |
1119 | } | 1123 | } |
1120 | 1124 | ||
@@ -1126,7 +1130,7 @@ fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders<Ty> { | |||
1126 | if db.type_alias_data(t).is_extern { | 1130 | if db.type_alias_data(t).is_extern { |
1127 | Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner)) | 1131 | Binders::new(0, TyKind::ForeignType(crate::to_foreign_def_id(t)).intern(&Interner)) |
1128 | } else { | 1132 | } else { |
1129 | let substs = Substs::bound_vars(&generics, DebruijnIndex::INNERMOST); | 1133 | let substs = Substitution::bound_vars(&generics, DebruijnIndex::INNERMOST); |
1130 | let type_ref = &db.type_alias_data(t).type_ref; | 1134 | let type_ref = &db.type_alias_data(t).type_ref; |
1131 | let inner = ctx.lower_ty(type_ref.as_ref().unwrap_or(&TypeRef::Error)); | 1135 | let inner = ctx.lower_ty(type_ref.as_ref().unwrap_or(&TypeRef::Error)); |
1132 | Binders::new(substs.len(), inner) | 1136 | 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::{ | |||
21 | primitive::{self, FloatTy, IntTy, UintTy}, | 21 | primitive::{self, FloatTy, IntTy, UintTy}, |
22 | utils::all_super_traits, | 22 | utils::all_super_traits, |
23 | AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner, | 23 | AdtId, Canonical, DebruijnIndex, FnPointer, FnSig, ForeignDefId, InEnvironment, Interner, |
24 | Scalar, Substs, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, | 24 | Scalar, Substitution, TraitEnvironment, TraitRef, Ty, TyKind, TypeWalk, |
25 | }; | 25 | }; |
26 | 26 | ||
27 | /// This is used as a key for indexing impls. | 27 | /// This is used as a key for indexing impls. |
@@ -672,10 +672,10 @@ pub(crate) fn inherent_impl_substs( | |||
672 | db: &dyn HirDatabase, | 672 | db: &dyn HirDatabase, |
673 | impl_id: ImplId, | 673 | impl_id: ImplId, |
674 | self_ty: &Canonical<Ty>, | 674 | self_ty: &Canonical<Ty>, |
675 | ) -> Option<Substs> { | 675 | ) -> Option<Substitution> { |
676 | // we create a var for each type parameter of the impl; we need to keep in | 676 | // we create a var for each type parameter of the impl; we need to keep in |
677 | // mind here that `self_ty` might have vars of its own | 677 | // mind here that `self_ty` might have vars of its own |
678 | let vars = Substs::build_for_def(db, impl_id) | 678 | let vars = Substitution::build_for_def(db, impl_id) |
679 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.kinds.len()) | 679 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, self_ty.kinds.len()) |
680 | .build(); | 680 | .build(); |
681 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); | 681 | let self_ty_with_vars = db.impl_self_ty(impl_id).subst(&vars); |
@@ -693,7 +693,7 @@ pub(crate) fn inherent_impl_substs( | |||
693 | 693 | ||
694 | /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past | 694 | /// This replaces any 'free' Bound vars in `s` (i.e. those with indices past |
695 | /// num_vars_to_keep) by `TyKind::Unknown`. | 695 | /// num_vars_to_keep) by `TyKind::Unknown`. |
696 | fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { | 696 | fn fallback_bound_vars(s: Substitution, num_vars_to_keep: usize) -> Substitution { |
697 | s.fold_binders( | 697 | s.fold_binders( |
698 | &mut |ty, binders| { | 698 | &mut |ty, binders| { |
699 | if let TyKind::BoundVar(bound) = ty.interned(&Interner) { | 699 | if let TyKind::BoundVar(bound) = ty.interned(&Interner) { |
@@ -716,13 +716,13 @@ fn transform_receiver_ty( | |||
716 | self_ty: &Canonical<Ty>, | 716 | self_ty: &Canonical<Ty>, |
717 | ) -> Option<Ty> { | 717 | ) -> Option<Ty> { |
718 | let substs = match function_id.lookup(db.upcast()).container { | 718 | let substs = match function_id.lookup(db.upcast()).container { |
719 | AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) | 719 | AssocContainerId::TraitId(_) => Substitution::build_for_def(db, function_id) |
720 | .push(self_ty.value.clone()) | 720 | .push(self_ty.value.clone()) |
721 | .fill_with_unknown() | 721 | .fill_with_unknown() |
722 | .build(), | 722 | .build(), |
723 | AssocContainerId::ImplId(impl_id) => { | 723 | AssocContainerId::ImplId(impl_id) => { |
724 | let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; | 724 | let impl_substs = inherent_impl_substs(db, impl_id, &self_ty)?; |
725 | Substs::build_for_def(db, function_id) | 725 | Substitution::build_for_def(db, function_id) |
726 | .use_parent_substs(&impl_substs) | 726 | .use_parent_substs(&impl_substs) |
727 | .fill_with_unknown() | 727 | .fill_with_unknown() |
728 | .build() | 728 | .build() |
@@ -768,7 +768,7 @@ fn generic_implements_goal( | |||
768 | self_ty: Canonical<Ty>, | 768 | self_ty: Canonical<Ty>, |
769 | ) -> Canonical<InEnvironment<super::Obligation>> { | 769 | ) -> Canonical<InEnvironment<super::Obligation>> { |
770 | let mut kinds = self_ty.kinds.to_vec(); | 770 | let mut kinds = self_ty.kinds.to_vec(); |
771 | let substs = super::Substs::build_for_def(db, trait_) | 771 | let substs = super::Substitution::build_for_def(db, trait_) |
772 | .push(self_ty.value) | 772 | .push(self_ty.value) |
773 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) | 773 | .fill_with_bound_vars(DebruijnIndex::INNERMOST, kinds.len()) |
774 | .build(); | 774 | .build(); |
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index fb3afaedc..af4f8bb11 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -216,6 +216,22 @@ fn expr_macro_expanded_in_various_places() { | |||
216 | } | 216 | } |
217 | 217 | ||
218 | #[test] | 218 | #[test] |
219 | fn expr_macro_expanded_in_stmts() { | ||
220 | check_infer( | ||
221 | r#" | ||
222 | macro_rules! id { ($($es:tt)*) => { $($es)* } } | ||
223 | fn foo() { | ||
224 | id! { let a = (); } | ||
225 | } | ||
226 | "#, | ||
227 | expect![[r#" | ||
228 | !0..8 'leta=();': () | ||
229 | 57..84 '{ ...); } }': () | ||
230 | "#]], | ||
231 | ); | ||
232 | } | ||
233 | |||
234 | #[test] | ||
219 | fn infer_type_value_macro_having_same_name() { | 235 | fn infer_type_value_macro_having_same_name() { |
220 | check_infer( | 236 | check_infer( |
221 | r#" | 237 | r#" |
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}; | |||
8 | use hir_def::{lang_item::LangItemTarget, TraitId}; | 8 | use hir_def::{lang_item::LangItemTarget, TraitId}; |
9 | use stdx::panic_context; | 9 | use stdx::panic_context; |
10 | 10 | ||
11 | use crate::{db::HirDatabase, DebruijnIndex, Substs}; | 11 | use crate::{db::HirDatabase, DebruijnIndex, Substitution}; |
12 | 12 | ||
13 | use super::{ | 13 | use super::{ |
14 | Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TyKind, TypeWalk, | 14 | Canonical, GenericPredicate, HirDisplay, ProjectionTy, TraitRef, Ty, TyKind, TypeWalk, |
@@ -252,7 +252,7 @@ fn solution_from_chalk( | |||
252 | } | 252 | } |
253 | 253 | ||
254 | #[derive(Clone, Debug, PartialEq, Eq)] | 254 | #[derive(Clone, Debug, PartialEq, Eq)] |
255 | pub struct SolutionVariables(pub Canonical<Substs>); | 255 | pub struct SolutionVariables(pub Canonical<Substitution>); |
256 | 256 | ||
257 | #[derive(Clone, Debug, PartialEq, Eq)] | 257 | #[derive(Clone, Debug, PartialEq, Eq)] |
258 | /// A (possible) solution for a proposed goal. | 258 | /// 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 232cf9cd0..bef6e7e9c 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -22,7 +22,7 @@ use crate::{ | |||
22 | to_assoc_type_id, | 22 | to_assoc_type_id, |
23 | utils::generics, | 23 | utils::generics, |
24 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate, | 24 | BoundVar, CallableDefId, CallableSig, DebruijnIndex, FnDefId, GenericPredicate, |
25 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TyKind, | 25 | ProjectionPredicate, ProjectionTy, Substitution, TraitRef, Ty, TyKind, |
26 | }; | 26 | }; |
27 | use mapping::{ | 27 | use mapping::{ |
28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, | 28 | convert_where_clauses, generic_predicate_to_inline_bound, make_binders, TypeAliasAsValue, |
@@ -221,7 +221,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
221 | let impl_bound = GenericPredicate::Implemented(TraitRef { | 221 | let impl_bound = GenericPredicate::Implemented(TraitRef { |
222 | trait_: future_trait, | 222 | trait_: future_trait, |
223 | // Self type as the first parameter. | 223 | // Self type as the first parameter. |
224 | substs: Substs::single( | 224 | substs: Substitution::single( |
225 | TyKind::BoundVar(BoundVar { | 225 | TyKind::BoundVar(BoundVar { |
226 | debruijn: DebruijnIndex::INNERMOST, | 226 | debruijn: DebruijnIndex::INNERMOST, |
227 | index: 0, | 227 | index: 0, |
@@ -236,7 +236,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
236 | projection_ty: ProjectionTy { | 236 | projection_ty: ProjectionTy { |
237 | associated_ty_id: to_assoc_type_id(future_output), | 237 | associated_ty_id: to_assoc_type_id(future_output), |
238 | // Self type as the first parameter. | 238 | // Self type as the first parameter. |
239 | substitution: Substs::single( | 239 | substitution: Substitution::single( |
240 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) | 240 | TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)) |
241 | .intern(&Interner), | 241 | .intern(&Interner), |
242 | ), | 242 | ), |
@@ -313,7 +313,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
313 | _closure_id: chalk_ir::ClosureId<Interner>, | 313 | _closure_id: chalk_ir::ClosureId<Interner>, |
314 | _substs: &chalk_ir::Substitution<Interner>, | 314 | _substs: &chalk_ir::Substitution<Interner>, |
315 | ) -> chalk_ir::Substitution<Interner> { | 315 | ) -> chalk_ir::Substitution<Interner> { |
316 | Substs::empty().to_chalk(self.db) | 316 | Substitution::empty().to_chalk(self.db) |
317 | } | 317 | } |
318 | 318 | ||
319 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { | 319 | fn trait_name(&self, trait_id: chalk_ir::TraitId<Interner>) -> String { |
@@ -392,7 +392,7 @@ pub(crate) fn associated_ty_data_query( | |||
392 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` | 392 | // Lower bounds -- we could/should maybe move this to a separate query in `lower` |
393 | let type_alias_data = db.type_alias_data(type_alias); | 393 | let type_alias_data = db.type_alias_data(type_alias); |
394 | let generic_params = generics(db.upcast(), type_alias.into()); | 394 | let generic_params = generics(db.upcast(), type_alias.into()); |
395 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 395 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
396 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 396 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
397 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 397 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
398 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 398 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
@@ -427,9 +427,9 @@ pub(crate) fn trait_datum_query( | |||
427 | let trait_data = db.trait_data(trait_); | 427 | let trait_data = db.trait_data(trait_); |
428 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); | 428 | debug!("trait {:?} = {:?}", trait_id, trait_data.name); |
429 | let generic_params = generics(db.upcast(), trait_.into()); | 429 | let generic_params = generics(db.upcast(), trait_.into()); |
430 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 430 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
431 | let flags = rust_ir::TraitFlags { | 431 | let flags = rust_ir::TraitFlags { |
432 | auto: trait_data.auto, | 432 | auto: trait_data.is_auto, |
433 | upstream: trait_.lookup(db.upcast()).container.krate() != krate, | 433 | upstream: trait_.lookup(db.upcast()).container.krate() != krate, |
434 | non_enumerable: true, | 434 | non_enumerable: true, |
435 | coinductive: false, // only relevant for Chalk testing | 435 | coinductive: false, // only relevant for Chalk testing |
@@ -496,7 +496,7 @@ pub(crate) fn struct_datum_query( | |||
496 | let upstream = adt_id.module(db.upcast()).krate() != krate; | 496 | let upstream = adt_id.module(db.upcast()).krate() != krate; |
497 | let where_clauses = { | 497 | let where_clauses = { |
498 | let generic_params = generics(db.upcast(), adt_id.into()); | 498 | let generic_params = generics(db.upcast(), adt_id.into()); |
499 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 499 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
500 | convert_where_clauses(db, adt_id.into(), &bound_vars) | 500 | convert_where_clauses(db, adt_id.into(), &bound_vars) |
501 | }; | 501 | }; |
502 | let flags = rust_ir::AdtFlags { | 502 | let flags = rust_ir::AdtFlags { |
@@ -545,7 +545,7 @@ fn impl_def_datum( | |||
545 | let impl_data = db.impl_data(impl_id); | 545 | let impl_data = db.impl_data(impl_id); |
546 | 546 | ||
547 | let generic_params = generics(db.upcast(), impl_id.into()); | 547 | let generic_params = generics(db.upcast(), impl_id.into()); |
548 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 548 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
549 | let trait_ = trait_ref.trait_; | 549 | let trait_ = trait_ref.trait_; |
550 | let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { | 550 | let impl_type = if impl_id.lookup(db.upcast()).container.krate() == krate { |
551 | rust_ir::ImplType::Local | 551 | rust_ir::ImplType::Local |
@@ -635,7 +635,7 @@ pub(crate) fn fn_def_datum_query( | |||
635 | let callable_def: CallableDefId = from_chalk(db, fn_def_id); | 635 | let callable_def: CallableDefId = from_chalk(db, fn_def_id); |
636 | let generic_params = generics(db.upcast(), callable_def.into()); | 636 | let generic_params = generics(db.upcast(), callable_def.into()); |
637 | let sig = db.callable_item_signature(callable_def); | 637 | let sig = db.callable_item_signature(callable_def); |
638 | let bound_vars = Substs::bound_vars(&generic_params, DebruijnIndex::INNERMOST); | 638 | let bound_vars = Substitution::bound_vars(&generic_params, DebruijnIndex::INNERMOST); |
639 | let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); | 639 | let where_clauses = convert_where_clauses(db, callable_def.into(), &bound_vars); |
640 | let bound = rust_ir::FnDefDatumBound { | 640 | let bound = rust_ir::FnDefDatumBound { |
641 | // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway | 641 | // 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::{ | |||
15 | primitive::UintTy, | 15 | primitive::UintTy, |
16 | traits::{Canonical, Obligation}, | 16 | traits::{Canonical, Obligation}, |
17 | AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, | 17 | AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, |
18 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 18 | ProjectionPredicate, ProjectionTy, Scalar, Substitution, TraitRef, Ty, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | use super::interner::*; | 21 | use super::interner::*; |
@@ -134,7 +134,7 @@ impl ToChalk for Ty { | |||
134 | .. | 134 | .. |
135 | }) => { | 135 | }) => { |
136 | assert_eq!(num_binders, 0); | 136 | assert_eq!(num_binders, 0); |
137 | let substs: Substs = from_chalk( | 137 | let substs: Substitution = from_chalk( |
138 | db, | 138 | db, |
139 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), | 139 | substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), |
140 | ); | 140 | ); |
@@ -213,14 +213,17 @@ fn array_to_chalk(db: &dyn HirDatabase, ty: Ty) -> chalk_ir::Ty<Interner> { | |||
213 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) | 213 | chalk_ir::TyKind::Array(arg, const_).intern(&Interner) |
214 | } | 214 | } |
215 | 215 | ||
216 | impl ToChalk for Substs { | 216 | impl ToChalk for Substitution { |
217 | type Chalk = chalk_ir::Substitution<Interner>; | 217 | type Chalk = chalk_ir::Substitution<Interner>; |
218 | 218 | ||
219 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { | 219 | fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> { |
220 | chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) | 220 | chalk_ir::Substitution::from_iter(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db))) |
221 | } | 221 | } |
222 | 222 | ||
223 | fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs { | 223 | fn from_chalk( |
224 | db: &dyn HirDatabase, | ||
225 | parameters: chalk_ir::Substitution<Interner>, | ||
226 | ) -> Substitution { | ||
224 | let tys = parameters | 227 | let tys = parameters |
225 | .iter(&Interner) | 228 | .iter(&Interner) |
226 | .map(|p| match p.ty(&Interner) { | 229 | .map(|p| match p.ty(&Interner) { |
@@ -228,7 +231,7 @@ impl ToChalk for Substs { | |||
228 | None => unimplemented!(), | 231 | None => unimplemented!(), |
229 | }) | 232 | }) |
230 | .collect(); | 233 | .collect(); |
231 | Substs(tys) | 234 | Substitution(tys) |
232 | } | 235 | } |
233 | } | 236 | } |
234 | 237 | ||
@@ -489,7 +492,7 @@ where | |||
489 | pub(super) fn convert_where_clauses( | 492 | pub(super) fn convert_where_clauses( |
490 | db: &dyn HirDatabase, | 493 | db: &dyn HirDatabase, |
491 | def: GenericDefId, | 494 | def: GenericDefId, |
492 | substs: &Substs, | 495 | substs: &Substitution, |
493 | ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> { | 496 | ) -> Vec<chalk_ir::QuantifiedWhereClause<Interner>> { |
494 | let generic_predicates = db.generic_predicates(def); | 497 | let generic_predicates = db.generic_predicates(def); |
495 | let mut result = Vec::with_capacity(generic_predicates.len()); | 498 | let mut result = Vec::with_capacity(generic_predicates.len()); |