From 7e541e69b1eaab3c242c864a0930cb263d2cbaf5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 3 Apr 2021 17:49:29 +0200 Subject: Add HasInterner bounds --- crates/hir_ty/src/chalk_cast.rs | 8 +++++++- crates/hir_ty/src/infer/unify.rs | 16 ++++++++++++---- crates/hir_ty/src/lib.rs | 15 +++++++++++---- crates/hir_ty/src/lower.rs | 4 ++-- crates/hir_ty/src/traits/chalk.rs | 2 +- crates/hir_ty/src/walk.rs | 4 ++-- 6 files changed, 35 insertions(+), 14 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/chalk_cast.rs b/crates/hir_ty/src/chalk_cast.rs index 1c3feabca..8bdd32ad6 100644 --- a/crates/hir_ty/src/chalk_cast.rs +++ b/crates/hir_ty/src/chalk_cast.rs @@ -5,7 +5,10 @@ use chalk_ir::{ interner::HasInterner, }; -use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause}; +use crate::{ + AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig, + ReturnTypeImplTraits, TraitRef, Ty, WhereClause, +}; macro_rules! has_interner { ($t:ty) => { @@ -24,3 +27,6 @@ macro_rules! transitive_impl { } }; } + +has_interner!(CallableSig); +has_interner!(ReturnTypeImplTraits); diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2ea9dd920..3732d8ebd 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -2,7 +2,9 @@ use std::borrow::Cow; -use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind}; +use chalk_ir::{ + interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind, +}; use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use super::{DomainGoal, InferenceContext}; @@ -34,7 +36,10 @@ where } #[derive(Debug)] -pub(super) struct Canonicalized { +pub(super) struct Canonicalized +where + T: HasInterner, +{ pub(super) value: Canonical, free_vars: Vec<(InferenceVar, TyVariableKind)>, } @@ -76,7 +81,10 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { ) } - fn into_canonicalized(self, result: T) -> Canonicalized { + fn into_canonicalized>( + self, + result: T, + ) -> Canonicalized { let kinds = self .free_vars .iter() @@ -108,7 +116,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { } } -impl Canonicalized { +impl> Canonicalized { pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty { ty.fold_binders( &mut |ty, binders| { diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 5fa8b3296..23dec7040 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs @@ -33,7 +33,11 @@ mod test_db; use std::sync::Arc; use base_db::salsa; -use chalk_ir::UintTy; +use chalk_ir::{ + cast::{CastTo, Caster}, + interner::HasInterner, + UintTy, +}; use hir_def::{ expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId, TypeParamId, @@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option { pub fn wrap_empty_binders(value: T) -> Binders where - T: TypeWalk, + T: TypeWalk + HasInterner, { Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE)) } -pub fn make_only_type_binders(num_vars: usize, value: T) -> Binders { +pub fn make_only_type_binders>( + num_vars: usize, + value: T, +) -> Binders { Binders::new( VariableKinds::from_iter( &Interner, @@ -132,7 +139,7 @@ pub fn make_only_type_binders(num_vars: usize, value: T) -> Binders { } // FIXME: get rid of this -pub fn make_canonical( +pub fn make_canonical>( value: T, kinds: impl IntoIterator, ) -> Canonical { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index e6903e189..d4ba707b4 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, Safety}; +use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety}; use hir_def::{ adt::StructKind, builtin_type::BuiltinType, @@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut } } -fn make_binders(generics: &Generics, value: T) -> Binders { +fn make_binders>(generics: &Generics, value: T) -> Binders { crate::make_only_type_binders(generics.len(), value) } diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 090f6492b..a5aa40c10 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use log::debug; -use chalk_ir::{fold::shift::Shift, CanonicalVarKinds}; +use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds}; use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; use base_db::{salsa::InternKey, CrateId}; diff --git a/crates/hir_ty/src/walk.rs b/crates/hir_ty/src/walk.rs index 873d563c0..c1aecdafc 100644 --- a/crates/hir_ty/src/walk.rs +++ b/crates/hir_ty/src/walk.rs @@ -3,7 +3,7 @@ use std::mem; -use chalk_ir::DebruijnIndex; +use chalk_ir::{interner::HasInterner, DebruijnIndex}; use crate::{ utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg, @@ -320,7 +320,7 @@ impl TypeWalk for Substitution { } } -impl TypeWalk for Binders { +impl> TypeWalk for Binders { fn walk(&self, f: &mut impl FnMut(&Ty)) { self.skip_binders().walk(f); } -- cgit v1.2.3