diff options
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 14 |
2 files changed, 12 insertions, 11 deletions
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index d887e21a2..744f30a93 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -8,7 +8,8 @@ use chalk_ir::{cast::Cast, Mutability, TyVariableKind}; | |||
8 | use hir_def::lang_item::LangItemTarget; | 8 | use hir_def::lang_item::LangItemTarget; |
9 | 9 | ||
10 | use crate::{ | 10 | use crate::{ |
11 | autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty, TyKind, | 11 | autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty, |
12 | TyBuilder, TyKind, | ||
12 | }; | 13 | }; |
13 | 14 | ||
14 | use super::{InEnvironment, InferenceContext}; | 15 | use super::{InEnvironment, InferenceContext}; |
@@ -44,8 +45,8 @@ impl<'a> InferenceContext<'a> { | |||
44 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 | 45 | // https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916 |
45 | let sig1 = ty1.callable_sig(self.db).expect("FnDef without callable sig"); | 46 | let sig1 = ty1.callable_sig(self.db).expect("FnDef without callable sig"); |
46 | let sig2 = ty2.callable_sig(self.db).expect("FnDef without callable sig"); | 47 | let sig2 = ty2.callable_sig(self.db).expect("FnDef without callable sig"); |
47 | let ptr_ty1 = Ty::fn_ptr(sig1); | 48 | let ptr_ty1 = TyBuilder::fn_ptr(sig1); |
48 | let ptr_ty2 = Ty::fn_ptr(sig2); | 49 | let ptr_ty2 = TyBuilder::fn_ptr(sig2); |
49 | self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) | 50 | self.coerce_merge_branch(&ptr_ty1, &ptr_ty2) |
50 | } else { | 51 | } else { |
51 | cov_mark::hit!(coerce_merge_fail_fallback); | 52 | cov_mark::hit!(coerce_merge_fail_fallback); |
@@ -95,7 +96,7 @@ impl<'a> InferenceContext<'a> { | |||
95 | (TyKind::FnDef(..), TyKind::Function { .. }) => match from_ty.callable_sig(self.db) { | 96 | (TyKind::FnDef(..), TyKind::Function { .. }) => match from_ty.callable_sig(self.db) { |
96 | None => return false, | 97 | None => return false, |
97 | Some(sig) => { | 98 | Some(sig) => { |
98 | from_ty = Ty::fn_ptr(sig); | 99 | from_ty = TyBuilder::fn_ptr(sig); |
99 | } | 100 | } |
100 | }, | 101 | }, |
101 | 102 | ||
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index b6173d87c..fd44efa07 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -818,14 +818,8 @@ impl TyBuilder { | |||
818 | pub fn unit() -> Ty { | 818 | pub fn unit() -> Ty { |
819 | TyKind::Tuple(0, Substitution::empty(&Interner)).intern(&Interner) | 819 | TyKind::Tuple(0, Substitution::empty(&Interner)).intern(&Interner) |
820 | } | 820 | } |
821 | } | ||
822 | |||
823 | impl Ty { | ||
824 | pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty { | ||
825 | TyKind::Adt(AdtId(adt), substs).intern(&Interner) | ||
826 | } | ||
827 | 821 | ||
828 | pub fn fn_ptr(sig: CallableSig) -> Self { | 822 | pub fn fn_ptr(sig: CallableSig) -> Ty { |
829 | TyKind::Function(FnPointer { | 823 | TyKind::Function(FnPointer { |
830 | num_args: sig.params().len(), | 824 | num_args: sig.params().len(), |
831 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, | 825 | sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, |
@@ -833,6 +827,12 @@ impl Ty { | |||
833 | }) | 827 | }) |
834 | .intern(&Interner) | 828 | .intern(&Interner) |
835 | } | 829 | } |
830 | } | ||
831 | |||
832 | impl Ty { | ||
833 | pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty { | ||
834 | TyKind::Adt(AdtId(adt), substs).intern(&Interner) | ||
835 | } | ||
836 | 836 | ||
837 | pub fn builtin(builtin: BuiltinType) -> Self { | 837 | pub fn builtin(builtin: BuiltinType) -> Self { |
838 | match builtin { | 838 | match builtin { |