aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-28 22:54:07 +0000
committerGitHub <[email protected]>2021-02-28 22:54:07 +0000
commit5df3ee8274fdb7cdeb2b0871b4efea8cbf4724a1 (patch)
treec1769a152888b97134e3f3811d4504f467ce1047 /crates/hir_ty/src/infer
parent72457d022d704c47ab9dbfee6a1b29063cc9cc5d (diff)
parent407196b8c0f23e3ddc26e789b84542b1fd9b0eb8 (diff)
Merge #7816
7816: Lift Ty::Fn into a struct r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r--crates/hir_ty/src/infer/coerce.rs4
-rw-r--r--crates/hir_ty/src/infer/expr.rs15
2 files changed, 9 insertions, 10 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs
index cd5fb3252..4cca35904 100644
--- a/crates/hir_ty/src/infer/coerce.rs
+++ b/crates/hir_ty/src/infer/coerce.rs
@@ -89,14 +89,14 @@ impl<'a> InferenceContext<'a> {
89 | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false, 89 | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false,
90 90
91 // `{function_type}` -> `fn()` 91 // `{function_type}` -> `fn()`
92 (Ty::FnDef(..), Ty::FnPtr { .. }) => match from_ty.callable_sig(self.db) { 92 (Ty::FnDef(..), Ty::Function { .. }) => match from_ty.callable_sig(self.db) {
93 None => return false, 93 None => return false,
94 Some(sig) => { 94 Some(sig) => {
95 from_ty = Ty::fn_ptr(sig); 95 from_ty = Ty::fn_ptr(sig);
96 } 96 }
97 }, 97 },
98 98
99 (Ty::Closure { substs, .. }, Ty::FnPtr { .. }) => { 99 (Ty::Closure(.., substs), Ty::Function { .. }) => {
100 from_ty = substs[0].clone(); 100 from_ty = substs[0].clone();
101 } 101 }
102 102
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs
index 98bc23173..23d4ac8ef 100644
--- a/crates/hir_ty/src/infer/expr.rs
+++ b/crates/hir_ty/src/infer/expr.rs
@@ -18,8 +18,8 @@ use crate::{
18 primitive::{self, UintTy}, 18 primitive::{self, UintTy},
19 traits::{FnTrait, InEnvironment}, 19 traits::{FnTrait, InEnvironment},
20 utils::{generics, variant_data, Generics}, 20 utils::{generics, variant_data, Generics},
21 Binders, CallableDefId, InferTy, Mutability, Obligation, OpaqueTyId, Rawness, Scalar, Substs, 21 Binders, CallableDefId, FnPointer, FnSig, InferTy, Mutability, Obligation, OpaqueTyId, Rawness,
22 TraitRef, Ty, 22 Scalar, Substs, TraitRef, Ty,
23}; 23};
24 24
25use super::{ 25use super::{
@@ -247,13 +247,12 @@ impl<'a> InferenceContext<'a> {
247 None => self.table.new_type_var(), 247 None => self.table.new_type_var(),
248 }; 248 };
249 sig_tys.push(ret_ty.clone()); 249 sig_tys.push(ret_ty.clone());
250 let sig_ty = Ty::FnPtr { 250 let sig_ty = Ty::Function(FnPointer {
251 num_args: sig_tys.len() as u16 - 1, 251 num_args: sig_tys.len() - 1,
252 is_varargs: false, 252 sig: FnSig { variadic: false },
253 substs: Substs(sig_tys.clone().into()), 253 substs: Substs(sig_tys.clone().into()),
254 }; 254 });
255 let closure_ty = 255 let closure_ty = Ty::Closure(self.owner, tgt_expr, Substs::single(sig_ty));
256 Ty::Closure { def: self.owner, expr: tgt_expr, substs: Substs::single(sig_ty) };
257 256
258 // Eagerly try to relate the closure type with the expected 257 // Eagerly try to relate the closure type with the expected
259 // type, otherwise we often won't have enough information to 258 // type, otherwise we often won't have enough information to