Move Ty::fn_ptr to TyBuilder

This commit is contained in:
Florian Diebold 2021-04-03 20:27:57 +02:00
parent b0fe3d929f
commit e6f007d9a8
2 changed files with 12 additions and 11 deletions

View File

@ -8,7 +8,8 @@
use hir_def::lang_item::LangItemTarget;
use crate::{
autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty, TyKind,
autoderef, to_chalk_trait_id, traits::Solution, Interner, Substitution, TraitRef, Ty,
TyBuilder, TyKind,
};
use super::{InEnvironment, InferenceContext};
@ -44,8 +45,8 @@ pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty {
// https://github.com/rust-lang/rust/blob/7b805396bf46dce972692a6846ce2ad8481c5f85/src/librustc_typeck/check/coercion.rs#L877-L916
let sig1 = ty1.callable_sig(self.db).expect("FnDef without callable sig");
let sig2 = ty2.callable_sig(self.db).expect("FnDef without callable sig");
let ptr_ty1 = Ty::fn_ptr(sig1);
let ptr_ty2 = Ty::fn_ptr(sig2);
let ptr_ty1 = TyBuilder::fn_ptr(sig1);
let ptr_ty2 = TyBuilder::fn_ptr(sig2);
self.coerce_merge_branch(&ptr_ty1, &ptr_ty2)
} else {
cov_mark::hit!(coerce_merge_fail_fallback);
@ -95,7 +96,7 @@ fn coerce_inner(&mut self, mut from_ty: Ty, to_ty: &Ty) -> bool {
(TyKind::FnDef(..), TyKind::Function { .. }) => match from_ty.callable_sig(self.db) {
None => return false,
Some(sig) => {
from_ty = Ty::fn_ptr(sig);
from_ty = TyBuilder::fn_ptr(sig);
}
},

View File

@ -818,14 +818,8 @@ impl TyBuilder {
pub fn unit() -> Ty {
TyKind::Tuple(0, Substitution::empty(&Interner)).intern(&Interner)
}
}
impl Ty {
pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty {
TyKind::Adt(AdtId(adt), substs).intern(&Interner)
}
pub fn fn_ptr(sig: CallableSig) -> Self {
pub fn fn_ptr(sig: CallableSig) -> Ty {
TyKind::Function(FnPointer {
num_args: sig.params().len(),
sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs },
@ -833,6 +827,12 @@ pub fn fn_ptr(sig: CallableSig) -> Self {
})
.intern(&Interner)
}
}
impl Ty {
pub fn adt_ty(adt: hir_def::AdtId, substs: Substitution) -> Ty {
TyKind::Adt(AdtId(adt), substs).intern(&Interner)
}
pub fn builtin(builtin: BuiltinType) -> Self {
match builtin {