Skip to content

Commit 9bce539

Browse files
committed
Add FnDef and FnDefId to chalk-ir
1 parent 03c7f3d commit 9bce539

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

chalk-ir/src/cast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ where
303303
}
304304
}
305305

306+
impl<I> CastTo<TypeName<I>> for FnDefId<I>
307+
where
308+
I: Interner,
309+
{
310+
fn cast_to(self, _interner: &I) -> TypeName<I> {
311+
TypeName::FnDef(self)
312+
}
313+
}
314+
306315
impl<T> CastTo<T> for &T
307316
where
308317
T: Clone + HasInterner,

chalk-ir/src/debug.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ impl<I: Interner> Debug for AssocTypeId<I> {
2121
}
2222
}
2323

24+
impl<I: Interner> Debug for FnDefId<I> {
25+
fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
26+
I::debug_fn_def_id(*self, fmt).unwrap_or_else(|| write!(fmt, "FnDefId({:?})", self.0))
27+
}
28+
}
29+
2430
impl<I: Interner> Debug for Ty<I> {
2531
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), Error> {
2632
I::debug_ty(self, fmt).unwrap_or_else(|| write!(fmt, "{:?}", self.interned))
@@ -146,6 +152,7 @@ impl<I: Interner> Debug for TypeName<I> {
146152
TypeName::Tuple(arity) => write!(fmt, "{:?}", arity),
147153
TypeName::OpaqueType(opaque_ty) => write!(fmt, "!{:?}", opaque_ty),
148154
TypeName::Slice => write!(fmt, "{{slice}}"),
155+
TypeName::FnDef(fn_def) => write!(fmt, "{:?}", fn_def),
149156
TypeName::Raw(mutability) => write!(fmt, "{:?}", mutability),
150157
TypeName::Ref(mutability) => write!(fmt, "{:?}", mutability),
151158
TypeName::Error => write!(fmt, "{{error}}"),

chalk-ir/src/fold/boring_impls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ id_fold!(AdtId, transfer_adt_id);
281281
id_fold!(TraitId);
282282
id_fold!(AssocTypeId);
283283
id_fold!(OpaqueTyId);
284+
id_fold!(FnDefId);
284285

285286
impl<I: Interner, TI: TargetInterner<I>> SuperFold<I, TI> for ProgramClauseData<I> {
286287
fn super_fold_with<'i>(

chalk-ir/src/interner.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::ApplicationTy;
44
use crate::AssocTypeId;
55
use crate::CanonicalVarKind;
66
use crate::CanonicalVarKinds;
7+
use crate::FnDefId;
78
use crate::GenericArg;
89
use crate::GenericArgData;
910
use crate::Goal;
@@ -206,6 +207,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
206207
None
207208
}
208209

210+
#[allow(unused_variables)]
211+
fn debug_fn_def_id(
212+
fn_def_id: FnDefId<Self>,
213+
fmt: &mut fmt::Formatter<'_>,
214+
) -> Option<fmt::Result> {
215+
None
216+
}
217+
209218
/// Prints the debug representation of an alias. To get good
210219
/// results, this requires inspecting TLS, and is difficult to
211220
/// code without reference to a specific interner (and hence

chalk-ir/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ pub enum TypeName<I: Interner> {
169169
/// a placeholder for opaque types like `impl Trait`
170170
OpaqueType(OpaqueTyId<I>),
171171

172+
/// a function definition
173+
FnDef(FnDefId<I>),
174+
172175
/// the string primitive type
173176
Str,
174177

@@ -237,6 +240,9 @@ pub struct AssocTypeId<I: Interner>(pub I::DefId);
237240
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
238241
pub struct OpaqueTyId<I: Interner>(pub I::DefId);
239242

243+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
244+
pub struct FnDefId<I: Interner>(pub I::DefId);
245+
240246
impl_debugs!(ImplId, ClauseId);
241247

242248
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, HasInterner)]

chalk-ir/src/visit/boring_impls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//! The more interesting impls of `Visit` remain in the `visit` module.
66
77
use crate::{
8-
AdtId, AssocTypeId, ClausePriority, DebruijnIndex, FloatTy, GenericArg, Goals, ImplId, IntTy,
9-
Interner, Mutability, OpaqueTyId, PlaceholderIndex, ProgramClause, ProgramClauseData,
8+
AdtId, AssocTypeId, ClausePriority, DebruijnIndex, FloatTy, FnDefId, GenericArg, Goals, ImplId,
9+
IntTy, Interner, Mutability, OpaqueTyId, PlaceholderIndex, ProgramClause, ProgramClauseData,
1010
ProgramClauses, QuantifiedWhereClauses, QuantifierKind, Scalar, Substitution, SuperVisit,
1111
TraitId, UintTy, UniverseIndex, Visit, VisitResult, Visitor,
1212
};
@@ -236,6 +236,7 @@ id_visit!(AdtId);
236236
id_visit!(TraitId);
237237
id_visit!(OpaqueTyId);
238238
id_visit!(AssocTypeId);
239+
id_visit!(FnDefId);
239240

240241
impl<I: Interner> SuperVisit<I> for ProgramClause<I> {
241242
fn super_visit_with<'i, R: VisitResult>(

0 commit comments

Comments
 (0)