aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer/expr.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-03-16 16:58:48 +0000
committerGitHub <[email protected]>2021-03-16 16:58:48 +0000
commit4771a5f1ca810a3f3697aea8da5af6dc8c03bbd1 (patch)
treedc4ed41e25efae7b6f76fcf18b6b6eb68170e7a9 /crates/hir_ty/src/infer/expr.rs
parent00c80b208bcbe52b13bbd03cb62e24b2d2075edf (diff)
parentce2cae45b5242d59b744018dd79bc2ab74670edc (diff)
Merge #8041
8041: Rename Substs -> Substitution r=flodiebold a=flodiebold Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer/expr.rs')
-rw-r--r--crates/hir_ty/src/infer/expr.rs37
1 files changed, 19 insertions, 18 deletions
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
28use super::{ 28use 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) {