From eea777c7148ac6c52434e8ea4913cdb50a466a3e Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 16:30:02 +0100 Subject: [PATCH] Use chalk_ir::FnSig --- crates/hir_ty/src/autoderef.rs | 5 ++++- crates/hir_ty/src/infer/expr.rs | 2 +- crates/hir_ty/src/lib.rs | 13 ++++++------- crates/hir_ty/src/lower.rs | 4 ++-- crates/hir_ty/src/traits/chalk/mapping.rs | 19 +++++++++---------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index d5c2b9a20bb..56c6b92d4e0 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs @@ -84,7 +84,10 @@ fn deref_by_trait( let projection = super::traits::ProjectionPredicate { ty: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())) .intern(&Interner), - projection_ty: super::ProjectionTy { associated_ty_id: to_assoc_type_id(target), substitution: parameters }, + projection_ty: super::ProjectionTy { + associated_ty_id: to_assoc_type_id(target), + substitution: parameters, + }, }; let obligation = super::Obligation::Projection(projection); diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index b7870e77174..55163c963f2 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -261,7 +261,7 @@ impl<'a> InferenceContext<'a> { sig_tys.push(ret_ty.clone()); let sig_ty = TyKind::Function(FnPointer { num_args: sig_tys.len() - 1, - sig: FnSig { variadic: false }, + sig: FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic: false }, substs: Substs(sig_tys.clone().into()), }) .intern(&Interner); diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index ddcee20844f..bc7a7369ab7 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -46,7 +46,7 @@ pub use lower::{ }; pub use traits::{InEnvironment, Obligation, ProjectionPredicate, TraitEnvironment}; -pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Scalar, TyVariableKind}; +pub use chalk_ir::{AdtId, BoundVar, DebruijnIndex, Mutability, Safety, Scalar, TyVariableKind}; pub use crate::traits::chalk::Interner; @@ -105,10 +105,7 @@ impl TypeWalk for ProjectionTy { } } -#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] -pub struct FnSig { - pub variadic: bool, -} +pub type FnSig = chalk_ir::FnSig; #[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct FnPointer { @@ -643,7 +640,7 @@ impl Ty { pub fn fn_ptr(sig: CallableSig) -> Self { TyKind::Function(FnPointer { num_args: sig.params().len(), - sig: FnSig { variadic: sig.is_varargs }, + sig: FnSig { abi: (), safety: Safety::Safe, variadic: sig.is_varargs }, substs: Substs(sig.params_and_return), }) .intern(&Interner) @@ -945,7 +942,9 @@ impl Ty { } } TyKind::Alias(AliasTy::Projection(projection_ty)) => { - match from_assoc_type_id(projection_ty.associated_ty_id).lookup(db.upcast()).container + match from_assoc_type_id(projection_ty.associated_ty_id) + .lookup(db.upcast()) + .container { AssocContainerId::TraitId(trait_id) => Some(trait_id), _ => None, diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 17eb29911bb..76b2124af95 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -8,7 +8,7 @@ use std::{iter, sync::Arc}; use base_db::CrateId; -use chalk_ir::{cast::Cast, Mutability}; +use chalk_ir::{cast::Cast, Mutability, Safety}; use hir_def::{ adt::StructKind, builtin_type::BuiltinType, @@ -181,7 +181,7 @@ impl<'a> TyLoweringContext<'a> { let substs = Substs(params.iter().map(|tr| self.lower_ty(tr)).collect()); TyKind::Function(FnPointer { num_args: substs.len() - 1, - sig: FnSig { variadic: *is_varargs }, + sig: FnSig { abi: (), safety: Safety::Safe, variadic: *is_varargs }, substs, }) .intern(&Interner) diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 68effbbf3d2..1a6fca611ad 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs @@ -14,7 +14,7 @@ use crate::{ from_assoc_type_id, primitive::UintTy, traits::{Canonical, Obligation}, - AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, + AliasTy, CallableDefId, FnPointer, GenericPredicate, InEnvironment, OpaqueTy, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitRef, Ty, }; @@ -27,11 +27,11 @@ impl ToChalk for Ty { match self.0 { TyKind::Ref(m, parameters) => ref_to_chalk(db, m, parameters), TyKind::Array(parameters) => array_to_chalk(db, parameters), - TyKind::Function(FnPointer { sig: FnSig { variadic }, substs, .. }) => { + TyKind::Function(FnPointer { sig, substs, .. }) => { let substitution = chalk_ir::FnSubst(substs.to_chalk(db).shifted_in(&Interner)); chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders: 0, - sig: chalk_ir::FnSig { abi: (), safety: chalk_ir::Safety::Safe, variadic }, + sig, substitution, }) .intern(&Interner) @@ -121,7 +121,10 @@ impl ToChalk for Ty { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(proj)) => { let associated_ty = proj.associated_ty_id; let parameters = from_chalk(db, proj.substitution); - TyKind::Alias(AliasTy::Projection(ProjectionTy { associated_ty_id: associated_ty, substitution: parameters })) + TyKind::Alias(AliasTy::Projection(ProjectionTy { + associated_ty_id: associated_ty, + substitution: parameters, + })) } chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { let opaque_ty_id = opaque_ty.opaque_ty_id; @@ -130,7 +133,7 @@ impl ToChalk for Ty { } chalk_ir::TyKind::Function(chalk_ir::FnPointer { num_binders, - sig: chalk_ir::FnSig { variadic, .. }, + sig, substitution, .. }) => { @@ -139,11 +142,7 @@ impl ToChalk for Ty { db, substitution.0.shifted_out(&Interner).expect("fn ptr should have no binders"), ); - TyKind::Function(FnPointer { - num_args: (substs.len() - 1), - sig: FnSig { variadic }, - substs, - }) + TyKind::Function(FnPointer { num_args: (substs.len() - 1), sig, substs }) } chalk_ir::TyKind::BoundVar(idx) => TyKind::BoundVar(idx), chalk_ir::TyKind::InferenceVar(_iv, _kind) => TyKind::Unknown,