Skip to content

Commit 7e541e6

Browse files
committed
Add HasInterner bounds
1 parent 926bfef commit 7e541e6

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

crates/hir_ty/src/chalk_cast.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use chalk_ir::{
55
interner::HasInterner,
66
};
77

8-
use crate::{AliasEq, DomainGoal, GenericArg, GenericArgData, Interner, TraitRef, Ty, WhereClause};
8+
use crate::{
9+
AliasEq, CallableSig, DomainGoal, GenericArg, GenericArgData, Interner, PolyFnSig,
10+
ReturnTypeImplTraits, TraitRef, Ty, WhereClause,
11+
};
912

1013
macro_rules! has_interner {
1114
($t:ty) => {
@@ -24,3 +27,6 @@ macro_rules! transitive_impl {
2427
}
2528
};
2629
}
30+
31+
has_interner!(CallableSig);
32+
has_interner!(ReturnTypeImplTraits);

crates/hir_ty/src/infer/unify.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
use std::borrow::Cow;
44

5-
use chalk_ir::{FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind};
5+
use chalk_ir::{
6+
interner::HasInterner, FloatTy, IntTy, TyVariableKind, UniverseIndex, VariableKind,
7+
};
68
use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue};
79

810
use super::{DomainGoal, InferenceContext};
@@ -34,7 +36,10 @@ where
3436
}
3537

3638
#[derive(Debug)]
37-
pub(super) struct Canonicalized<T> {
39+
pub(super) struct Canonicalized<T>
40+
where
41+
T: HasInterner<Interner = Interner>,
42+
{
3843
pub(super) value: Canonical<T>,
3944
free_vars: Vec<(InferenceVar, TyVariableKind)>,
4045
}
@@ -76,7 +81,10 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
7681
)
7782
}
7883

79-
fn into_canonicalized<T>(self, result: T) -> Canonicalized<T> {
84+
fn into_canonicalized<T: HasInterner<Interner = Interner>>(
85+
self,
86+
result: T,
87+
) -> Canonicalized<T> {
8088
let kinds = self
8189
.free_vars
8290
.iter()
@@ -108,7 +116,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> {
108116
}
109117
}
110118

111-
impl<T> Canonicalized<T> {
119+
impl<T: HasInterner<Interner = Interner>> Canonicalized<T> {
112120
pub(super) fn decanonicalize_ty(&self, ty: Ty) -> Ty {
113121
ty.fold_binders(
114122
&mut |ty, binders| {

crates/hir_ty/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ mod test_db;
3333
use std::sync::Arc;
3434

3535
use base_db::salsa;
36-
use chalk_ir::UintTy;
36+
use chalk_ir::{
37+
cast::{CastTo, Caster},
38+
interner::HasInterner,
39+
UintTy,
40+
};
3741
use hir_def::{
3842
expr::ExprId, type_ref::Rawness, ConstParamId, LifetimeParamId, TraitId, TypeAliasId,
3943
TypeParamId,
@@ -115,12 +119,15 @@ pub fn param_idx(db: &dyn HirDatabase, id: TypeParamId) -> Option<usize> {
115119

116120
pub fn wrap_empty_binders<T>(value: T) -> Binders<T>
117121
where
118-
T: TypeWalk,
122+
T: TypeWalk + HasInterner<Interner = Interner>,
119123
{
120124
Binders::empty(&Interner, value.shifted_in_from(DebruijnIndex::ONE))
121125
}
122126

123-
pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
127+
pub fn make_only_type_binders<T: HasInterner<Interner = Interner>>(
128+
num_vars: usize,
129+
value: T,
130+
) -> Binders<T> {
124131
Binders::new(
125132
VariableKinds::from_iter(
126133
&Interner,
@@ -132,7 +139,7 @@ pub fn make_only_type_binders<T>(num_vars: usize, value: T) -> Binders<T> {
132139
}
133140

134141
// FIXME: get rid of this
135-
pub fn make_canonical<T>(
142+
pub fn make_canonical<T: HasInterner<Interner = Interner>>(
136143
value: T,
137144
kinds: impl IntoIterator<Item = TyVariableKind>,
138145
) -> Canonical<T> {

crates/hir_ty/src/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use std::{iter, sync::Arc};
99

1010
use base_db::CrateId;
11-
use chalk_ir::{cast::Cast, Mutability, Safety};
11+
use chalk_ir::{cast::Cast, interner::HasInterner, Mutability, Safety};
1212
use hir_def::{
1313
adt::StructKind,
1414
builtin_type::BuiltinType,
@@ -1307,6 +1307,6 @@ pub(crate) fn lower_to_chalk_mutability(m: hir_def::type_ref::Mutability) -> Mut
13071307
}
13081308
}
13091309

1310-
fn make_binders<T>(generics: &Generics, value: T) -> Binders<T> {
1310+
fn make_binders<T: HasInterner<Interner = Interner>>(generics: &Generics, value: T) -> Binders<T> {
13111311
crate::make_only_type_binders(generics.len(), value)
13121312
}

crates/hir_ty/src/traits/chalk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33

44
use log::debug;
55

6-
use chalk_ir::{fold::shift::Shift, CanonicalVarKinds};
6+
use chalk_ir::{fold::shift::Shift, interner::HasInterner, CanonicalVarKinds};
77
use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
88

99
use base_db::{salsa::InternKey, CrateId};

crates/hir_ty/src/walk.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use std::mem;
55

6-
use chalk_ir::DebruijnIndex;
6+
use chalk_ir::{interner::HasInterner, DebruijnIndex};
77

88
use crate::{
99
utils::make_mut_slice, AliasEq, AliasTy, Binders, CallableSig, FnSubst, GenericArg,
@@ -320,7 +320,7 @@ impl TypeWalk for Substitution {
320320
}
321321
}
322322

323-
impl<T: TypeWalk> TypeWalk for Binders<T> {
323+
impl<T: TypeWalk + HasInterner<Interner = Interner>> TypeWalk for Binders<T> {
324324
fn walk(&self, f: &mut impl FnMut(&Ty)) {
325325
self.skip_binders().walk(f);
326326
}

0 commit comments

Comments
 (0)