diff options
author | Lukas Wirth <lukastw97@gmail.com> | 2021-02-28 21:12:07 +0000 |
---|---|---|
committer | Lukas Wirth <lukastw97@gmail.com> | 2021-02-28 22:53:21 +0000 |
commit | 407196b8c0f23e3ddc26e789b84542b1fd9b0eb8 (patch) | |
tree | 8f088d09b8a7a017335b90aefbc33211568eb4c3 /crates/hir_ty/src/infer | |
parent | 23d7dbfa5e7ba2cebf8c3f79b5d31285d79c1527 (diff) |
Lift FnPointer into a struct
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 15 |
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 13240f790..b75d32b85 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 | ||
25 | use super::{ | 25 | use 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 |