From 407196b8c0f23e3ddc26e789b84542b1fd9b0eb8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 28 Feb 2021 22:12:07 +0100 Subject: Lift FnPointer into a struct --- crates/hir_ty/src/infer/coerce.rs | 4 ++-- crates/hir_ty/src/infer/expr.rs | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'crates/hir_ty/src/infer') 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> { | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false, // `{function_type}` -> `fn()` - (Ty::FnDef(..), Ty::FnPtr { .. }) => match from_ty.callable_sig(self.db) { + (Ty::FnDef(..), Ty::Function { .. }) => match from_ty.callable_sig(self.db) { None => return false, Some(sig) => { from_ty = Ty::fn_ptr(sig); } }, - (Ty::Closure { substs, .. }, Ty::FnPtr { .. }) => { + (Ty::Closure(.., substs), Ty::Function { .. }) => { from_ty = substs[0].clone(); } 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::{ primitive::{self, UintTy}, traits::{FnTrait, InEnvironment}, utils::{generics, variant_data, Generics}, - Binders, CallableDefId, InferTy, Mutability, Obligation, OpaqueTyId, Rawness, Scalar, Substs, - TraitRef, Ty, + Binders, CallableDefId, FnPointer, FnSig, InferTy, Mutability, Obligation, OpaqueTyId, Rawness, + Scalar, Substs, TraitRef, Ty, }; use super::{ @@ -247,13 +247,12 @@ impl<'a> InferenceContext<'a> { None => self.table.new_type_var(), }; sig_tys.push(ret_ty.clone()); - let sig_ty = Ty::FnPtr { - num_args: sig_tys.len() as u16 - 1, - is_varargs: false, + let sig_ty = Ty::Function(FnPointer { + num_args: sig_tys.len() - 1, + sig: FnSig { variadic: false }, substs: Substs(sig_tys.clone().into()), - }; - let closure_ty = - Ty::Closure { def: self.owner, expr: tgt_expr, substs: Substs::single(sig_ty) }; + }); + let closure_ty = Ty::Closure(self.owner, tgt_expr, Substs::single(sig_ty)); // Eagerly try to relate the closure type with the expected // type, otherwise we often won't have enough information to -- cgit v1.2.3