1 //! Encapsulates the concrete representation of core types such as types and goals.
3 use crate::AssocTypeId
;
4 use crate::CanonicalVarKind
;
5 use crate::CanonicalVarKinds
;
8 use crate::Constraints
;
10 use crate::ForeignDefId
;
11 use crate::GeneratorId
;
12 use crate::GenericArg
;
13 use crate::GenericArgData
;
17 use crate::InEnvironment
;
19 use crate::LifetimeData
;
21 use crate::OpaqueTyId
;
22 use crate::ProgramClause
;
23 use crate::ProgramClauseData
;
24 use crate::ProgramClauseImplication
;
25 use crate::ProgramClauses
;
26 use crate::ProjectionTy
;
27 use crate::QuantifiedWhereClause
;
28 use crate::QuantifiedWhereClauses
;
29 use crate::SeparatorTraitRef
;
30 use crate::Substitution
;
34 use crate::VariableKind
;
35 use crate::VariableKinds
;
38 use crate::{AdtId, TyKind}
;
39 use crate::{Const, ConstData}
;
40 use std
::fmt
::{self, Debug}
;
42 use std
::marker
::PhantomData
;
45 /// A "interner" encapsulates the concrete representation of
46 /// certain "core types" from chalk-ir. All the types in chalk-ir are
47 /// parameterized by a `I: Interner`, and so (e.g.) if they want to
48 /// store a type, they don't store a `Ty<I>` instance directly, but
49 /// rather prefer a `Ty<I>`. You can think of `I::Type` as the
50 /// interned representation (and, indeed, it may well be an interned
51 /// pointer, e.g. in rustc).
53 /// Type families allow chalk to be embedded in different contexts
54 /// where the concrete representation of core types varies. They also
55 /// allow us to write generic code that reasons about multiple
56 /// distinct sets of types by using distinct generic type parameters
57 /// (e.g., `SourceI` and `TargetI`) -- even if those type parameters
58 /// wind up being mapped to the same underlying type families in the
60 pub trait Interner
: Debug
+ Copy
+ Eq
+ Hash
+ Sized
{
61 /// "Interned" representation of types. In normal user code,
62 /// `Self::InternedType` is not referenced. Instead, we refer to
63 /// `Ty<Self>`, which wraps this type.
65 /// An `InternedType` must be something that can be created from a
66 /// `TyKind` (by the [`intern_ty`][Self::intern_ty] method) and then later
67 /// converted back (by the [`ty_data`][Self::ty_data] method). The interned form
68 /// must also introduce indirection, either via a `Box`, `&`, or
69 /// other pointer type.
70 type InternedType
: Debug
+ Clone
+ Eq
+ Hash
;
72 /// "Interned" representation of lifetimes. In normal user code,
73 /// `Self::InternedLifetime` is not referenced. Instead, we refer to
74 /// `Lifetime<Self>`, which wraps this type.
76 /// An `InternedLifetime` must be something that can be created
77 /// from a `LifetimeData` (by the [`intern_lifetime`][Self::intern_lifetime] method) and
78 /// then later converted back (by the [`lifetime_data`][Self::lifetime_data] method).
79 type InternedLifetime
: Debug
+ Clone
+ Eq
+ Hash
;
81 /// "Interned" representation of const expressions. In normal user code,
82 /// `Self::InternedConst` is not referenced. Instead, we refer to
83 /// `Const<Self>`, which wraps this type.
85 /// An `InternedConst` must be something that can be created
86 /// from a `ConstData` (by the [`intern_const`][Self::intern_const] method) and
87 /// then later converted back (by the [`const_data`][Self::const_data] method).
88 type InternedConst
: Debug
+ Clone
+ Eq
+ Hash
;
90 /// "Interned" representation of an evaluated const value.
91 /// `Self::InternedConcreteConst` is not referenced. Instead,
92 /// we refer to `ConcreteConst<Self>`, which wraps this type.
94 /// `InternedConcreteConst` instances are not created by chalk,
95 /// it can only make a query asking about equality of two
97 type InternedConcreteConst
: Debug
+ Clone
+ Eq
+ Hash
;
99 /// "Interned" representation of a "generic parameter", which can
100 /// be either a type or a lifetime. In normal user code,
101 /// `Self::InternedGenericArg` is not referenced. Instead, we refer to
102 /// `GenericArg<Self>`, which wraps this type.
104 /// An `InternedType` is created by `intern_generic_arg` and can be
105 /// converted back to its underlying data via `generic_arg_data`.
106 type InternedGenericArg
: Debug
+ Clone
+ Eq
+ Hash
;
108 /// "Interned" representation of a "goal". In normal user code,
109 /// `Self::InternedGoal` is not referenced. Instead, we refer to
110 /// `Goal<Self>`, which wraps this type.
112 /// An `InternedGoal` is created by `intern_goal` and can be
113 /// converted back to its underlying data via `goal_data`.
114 type InternedGoal
: Debug
+ Clone
+ Eq
+ Hash
;
116 /// "Interned" representation of a list of goals. In normal user code,
117 /// `Self::InternedGoals` is not referenced. Instead, we refer to
118 /// `Goals<Self>`, which wraps this type.
120 /// An `InternedGoals` is created by `intern_goals` and can be
121 /// converted back to its underlying data via `goals_data`.
122 type InternedGoals
: Debug
+ Clone
+ Eq
+ Hash
;
124 /// "Interned" representation of a "substitution". In normal user code,
125 /// `Self::InternedSubstitution` is not referenced. Instead, we refer to
126 /// `Substitution<Self>`, which wraps this type.
128 /// An `InternedSubstitution` is created by `intern_substitution` and can be
129 /// converted back to its underlying data via `substitution_data`.
130 type InternedSubstitution
: Debug
+ Clone
+ Eq
+ Hash
;
132 /// "Interned" representation of a list of program clauses. In normal user code,
133 /// `Self::InternedProgramClauses` is not referenced. Instead, we refer to
134 /// `ProgramClauses<Self>`, which wraps this type.
136 /// An `InternedProgramClauses` is created by `intern_program_clauses` and can be
137 /// converted back to its underlying data via `program_clauses_data`.
138 type InternedProgramClauses
: Debug
+ Clone
+ Eq
+ Hash
;
140 /// "Interned" representation of a "program clause". In normal user code,
141 /// `Self::InternedProgramClause` is not referenced. Instead, we refer to
142 /// `ProgramClause<Self>`, which wraps this type.
144 /// An `InternedProgramClause` is created by `intern_program_clause` and can be
145 /// converted back to its underlying data via `program_clause_data`.
146 type InternedProgramClause
: Debug
+ Clone
+ Eq
+ Hash
;
148 /// "Interned" representation of a list of quantified where clauses.
149 /// In normal user code, `Self::InternedQuantifiedWhereClauses` is not referenced.
150 /// Instead, we refer to `QuantifiedWhereClauses<Self>`, which wraps this type.
152 /// An `InternedQuantifiedWhereClauses` is created by `intern_quantified_where_clauses`
153 /// and can be converted back to its underlying data via `quantified_where_clauses_data`.
154 type InternedQuantifiedWhereClauses
: Debug
+ Clone
+ Eq
+ Hash
;
156 /// "Interned" representation of a list of variable kinds.
157 /// In normal user code, `Self::InternedVariableKinds` is not referenced.
158 /// Instead, we refer to `VariableKinds<Self>`, which wraps this type.
160 /// An `InternedVariableKinds` is created by `intern_generic_arg_kinds`
161 /// and can be converted back to its underlying data via `variable_kinds_data`.
162 type InternedVariableKinds
: Debug
+ Clone
+ Eq
+ Hash
;
164 /// "Interned" representation of a list of variable kinds with universe index.
165 /// In normal user code, `Self::InternedCanonicalVarKinds` is not referenced.
166 /// Instead, we refer to `CanonicalVarKinds<Self>`, which wraps this type.
168 /// An `InternedCanonicalVarKinds` is created by
169 /// `intern_canonical_var_kinds` and can be converted back
170 /// to its underlying data via `canonical_var_kinds_data`.
171 type InternedCanonicalVarKinds
: Debug
+ Clone
+ Eq
+ Hash
;
173 /// "Interned" representation of a list of region constraints.
174 /// In normal user code, `Self::InternedConstraints` is not referenced.
175 /// Instead, we refer to `Constraints<Self>`, which wraps this type.
177 /// An `InternedConstraints` is created by `intern_constraints`
178 /// and can be converted back to its underlying data via `constraints_data`.
179 type InternedConstraints
: Debug
+ Clone
+ Eq
+ Hash
;
181 /// "Interned" representation of a list of `chalk_ir::Variance`.
182 /// In normal user code, `Self::InternedVariances` is not referenced.
183 /// Instead, we refer to `Variances<Self>`, which wraps this type.
185 /// An `InternedVariances` is created by
186 /// `intern_variances` and can be converted back
187 /// to its underlying data via `variances_data`.
188 type InternedVariances
: Debug
+ Clone
+ Eq
+ Hash
;
190 /// The core "id" type used for trait-ids and the like.
191 type DefId
: Debug
+ Copy
+ Eq
+ Hash
;
193 /// The ID type for ADTs
194 type InternedAdtId
: Debug
+ Copy
+ Eq
+ Hash
;
196 /// Representation of identifiers.
197 type Identifier
: Debug
+ Clone
+ Eq
+ Hash
;
199 /// Representation of function ABI (e.g. calling convention).
200 type FnAbi
: Debug
+ Copy
+ Eq
+ Hash
;
202 /// Prints the debug representation of a type-kind-id.
203 /// Returns `None` to fallback to the default debug output.
204 #[allow(unused_variables)]
205 fn debug_adt_id(adt_id
: AdtId
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
209 /// Prints the debug representation of a type-kind-id.
210 /// Returns `None` to fallback to the default debug output (e.g.,
211 /// if no info about current program is available from TLS).
212 #[allow(unused_variables)]
214 trait_id
: TraitId
<Self>,
215 fmt
: &mut fmt
::Formatter
<'_
>,
216 ) -> Option
<fmt
::Result
> {
220 /// Prints the debug representation of a type-kind-id.
221 /// Returns `None` to fallback to the default debug output.
222 #[allow(unused_variables)]
223 fn debug_assoc_type_id(
224 type_id
: AssocTypeId
<Self>,
225 fmt
: &mut fmt
::Formatter
<'_
>,
226 ) -> Option
<fmt
::Result
> {
230 /// Prints the debug representation of an opaque type.
231 /// Returns `None` to fallback to the default debug output.
232 #[allow(unused_variables)]
233 fn debug_opaque_ty_id(
234 opaque_ty_id
: OpaqueTyId
<Self>,
235 fmt
: &mut fmt
::Formatter
<'_
>,
236 ) -> Option
<fmt
::Result
> {
240 /// Prints the debug representation of a function-def-id.
241 /// Returns `None` to fallback to the default debug output.
242 #[allow(unused_variables)]
244 fn_def_id
: FnDefId
<Self>,
245 fmt
: &mut fmt
::Formatter
<'_
>,
246 ) -> Option
<fmt
::Result
> {
250 /// Prints the debug representation of a closure id.
251 /// Returns `None` to fallback to the default debug output.
252 #[allow(unused_variables)]
254 fn_def_id
: ClosureId
<Self>,
255 fmt
: &mut fmt
::Formatter
<'_
>,
256 ) -> Option
<fmt
::Result
> {
260 /// Prints the debug representation of a foreign-def-id.
261 /// Returns `None` to fallback to the default debug output.
262 #[allow(unused_variables)]
263 fn debug_foreign_def_id(
264 foreign_def_id
: ForeignDefId
<Self>,
265 fmt
: &mut fmt
::Formatter
<'_
>,
266 ) -> Option
<fmt
::Result
> {
270 /// Prints the debug representation of an alias.
271 /// Returns `None` to fallback to the default debug output.
272 #[allow(unused_variables)]
273 fn debug_generator_id(
274 generator_id
: GeneratorId
<Self>,
275 fmt
: &mut fmt
::Formatter
<'_
>,
276 ) -> Option
<fmt
::Result
> {
280 /// Prints the debug representation of an alias. To get good
281 /// results, this requires inspecting TLS, and is difficult to
282 /// code without reference to a specific interner (and hence
283 /// fully known types).
285 /// Returns `None` to fallback to the default debug output (e.g.,
286 /// if no info about current program is available from TLS).
287 #[allow(unused_variables)]
288 fn debug_alias(alias
: &AliasTy
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
292 /// Prints the debug representation of a ProjectionTy.
293 /// Returns `None` to fallback to the default debug output.
294 #[allow(unused_variables)]
295 fn debug_projection_ty(
296 projection_ty
: &ProjectionTy
<Self>,
297 fmt
: &mut fmt
::Formatter
<'_
>,
298 ) -> Option
<fmt
::Result
> {
302 /// Prints the debug representation of an OpaqueTy.
303 /// Returns `None` to fallback to the default debug output.
304 #[allow(unused_variables)]
306 opaque_ty
: &OpaqueTy
<Self>,
307 fmt
: &mut fmt
::Formatter
<'_
>,
308 ) -> Option
<fmt
::Result
> {
312 /// Prints the debug representation of a type.
313 /// Returns `None` to fallback to the default debug output.
314 #[allow(unused_variables)]
315 fn debug_ty(ty
: &Ty
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
319 /// Prints the debug representation of a lifetime.
320 /// Returns `None` to fallback to the default debug output.
321 #[allow(unused_variables)]
323 lifetime
: &Lifetime
<Self>,
324 fmt
: &mut fmt
::Formatter
<'_
>,
325 ) -> Option
<fmt
::Result
> {
329 /// Prints the debug representation of a const.
330 /// Returns `None` to fallback to the default debug output.
331 #[allow(unused_variables)]
332 fn debug_const(constant
: &Const
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
336 /// Prints the debug representation of an parameter.
337 /// Returns `None` to fallback to the default debug output.
338 #[allow(unused_variables)]
339 fn debug_generic_arg(
340 generic_arg
: &GenericArg
<Self>,
341 fmt
: &mut fmt
::Formatter
<'_
>,
342 ) -> Option
<fmt
::Result
> {
346 /// Prints the debug representation of a parameter kinds list.
347 /// Returns `None` to fallback to the default debug output.
348 #[allow(unused_variables)]
349 fn debug_variable_kinds(
350 variable_kinds
: &VariableKinds
<Self>,
351 fmt
: &mut fmt
::Formatter
<'_
>,
352 ) -> Option
<fmt
::Result
> {
356 /// Prints the debug representation of a parameter kinds list, with angle brackets.
357 /// Returns `None` to fallback to the default debug output.
358 #[allow(unused_variables)]
359 fn debug_variable_kinds_with_angles(
360 variable_kinds
: &VariableKinds
<Self>,
361 fmt
: &mut fmt
::Formatter
<'_
>,
362 ) -> Option
<fmt
::Result
> {
366 /// Prints the debug representation of an parameter kinds list with universe index.
367 /// Returns `None` to fallback to the default debug output.
368 #[allow(unused_variables)]
369 fn debug_canonical_var_kinds(
370 canonical_var_kinds
: &CanonicalVarKinds
<Self>,
371 fmt
: &mut fmt
::Formatter
<'_
>,
372 ) -> Option
<fmt
::Result
> {
376 /// Prints the debug representation of an goal.
377 /// Returns `None` to fallback to the default debug output.
378 #[allow(unused_variables)]
379 fn debug_goal(goal
: &Goal
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
383 /// Prints the debug representation of a list of goals.
384 /// Returns `None` to fallback to the default debug output.
385 #[allow(unused_variables)]
386 fn debug_goals(goals
: &Goals
<Self>, fmt
: &mut fmt
::Formatter
<'_
>) -> Option
<fmt
::Result
> {
390 /// Prints the debug representation of a ProgramClauseImplication.
391 /// Returns `None` to fallback to the default debug output.
392 #[allow(unused_variables)]
393 fn debug_program_clause_implication(
394 pci
: &ProgramClauseImplication
<Self>,
395 fmt
: &mut fmt
::Formatter
<'_
>,
396 ) -> Option
<fmt
::Result
> {
400 /// Prints the debug representation of a ProgramClause.
401 /// Returns `None` to fallback to the default debug output.
402 #[allow(unused_variables)]
403 fn debug_program_clause(
404 clause
: &ProgramClause
<Self>,
405 fmt
: &mut fmt
::Formatter
<'_
>,
406 ) -> Option
<fmt
::Result
> {
410 /// Prints the debug representation of a ProgramClauses.
411 /// Returns `None` to fallback to the default debug output.
412 #[allow(unused_variables)]
413 fn debug_program_clauses(
414 clauses
: &ProgramClauses
<Self>,
415 fmt
: &mut fmt
::Formatter
<'_
>,
416 ) -> Option
<fmt
::Result
> {
420 /// Prints the debug representation of a Substitution.
421 /// Returns `None` to fallback to the default debug output.
422 #[allow(unused_variables)]
423 fn debug_substitution(
424 substitution
: &Substitution
<Self>,
425 fmt
: &mut fmt
::Formatter
<'_
>,
426 ) -> Option
<fmt
::Result
> {
430 /// Prints the debug representation of a SeparatorTraitRef.
431 /// Returns `None` to fallback to the default debug output.
432 #[allow(unused_variables)]
433 fn debug_separator_trait_ref(
434 separator_trait_ref
: &SeparatorTraitRef
<'_
, Self>,
435 fmt
: &mut fmt
::Formatter
<'_
>,
436 ) -> Option
<fmt
::Result
> {
440 /// Prints the debug representation of a QuantifiedWhereClauses.
441 /// Returns `None` to fallback to the default debug output.
442 #[allow(unused_variables)]
443 fn debug_quantified_where_clauses(
444 clauses
: &QuantifiedWhereClauses
<Self>,
445 fmt
: &mut fmt
::Formatter
<'_
>,
446 ) -> Option
<fmt
::Result
> {
450 /// Prints the debug representation of a Constraints.
451 /// Returns `None` to fallback to the default debug output.
452 #[allow(unused_variables)]
453 fn debug_constraints(
454 clauses
: &Constraints
<Self>,
455 fmt
: &mut fmt
::Formatter
<'_
>,
456 ) -> Option
<fmt
::Result
> {
460 /// Prints the debug representation of a Variances.
461 /// Returns `None` to fallback to the default debug output.
462 #[allow(unused_variables)]
464 variances
: &Variances
<Self>,
465 fmt
: &mut fmt
::Formatter
<'_
>,
466 ) -> Option
<fmt
::Result
> {
470 /// Create an "interned" type from `ty`. This is not normally
471 /// invoked directly; instead, you invoke `TyKind::intern` (which
472 /// will ultimately call this method).
473 fn intern_ty(self, kind
: TyKind
<Self>) -> Self::InternedType
;
475 /// Lookup the `TyKind` from an interned type.
476 fn ty_data(self, ty
: &Self::InternedType
) -> &TyData
<Self>;
478 /// Create an "interned" lifetime from `lifetime`. This is not
479 /// normally invoked directly; instead, you invoke
480 /// `LifetimeData::intern` (which will ultimately call this
482 fn intern_lifetime(self, lifetime
: LifetimeData
<Self>) -> Self::InternedLifetime
;
484 /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`.
485 fn lifetime_data(self, lifetime
: &Self::InternedLifetime
) -> &LifetimeData
<Self>;
487 /// Create an "interned" const from `const`. This is not
488 /// normally invoked directly; instead, you invoke
489 /// `ConstData::intern` (which will ultimately call this
491 fn intern_const(self, constant
: ConstData
<Self>) -> Self::InternedConst
;
493 /// Lookup the `ConstData` that was interned to create a `InternedConst`.
494 fn const_data(self, constant
: &Self::InternedConst
) -> &ConstData
<Self>;
496 /// Determine whether two concrete const values are equal.
499 ty
: &Self::InternedType
,
500 c1
: &Self::InternedConcreteConst
,
501 c2
: &Self::InternedConcreteConst
,
504 /// Create an "interned" parameter from `data`. This is not
505 /// normally invoked directly; instead, you invoke
506 /// `GenericArgData::intern` (which will ultimately call this
508 fn intern_generic_arg(self, data
: GenericArgData
<Self>) -> Self::InternedGenericArg
;
510 /// Lookup the `LifetimeData` that was interned to create a `InternedLifetime`.
511 fn generic_arg_data(self, lifetime
: &Self::InternedGenericArg
) -> &GenericArgData
<Self>;
513 /// Create an "interned" goal from `data`. This is not
514 /// normally invoked directly; instead, you invoke
515 /// `GoalData::intern` (which will ultimately call this
517 fn intern_goal(self, data
: GoalData
<Self>) -> Self::InternedGoal
;
519 /// Lookup the `GoalData` that was interned to create a `InternedGoal`.
520 fn goal_data(self, goal
: &Self::InternedGoal
) -> &GoalData
<Self>;
522 /// Create an "interned" goals from `data`. This is not
523 /// normally invoked directly; instead, you invoke
524 /// `GoalsData::intern` (which will ultimately call this
528 data
: impl IntoIterator
<Item
= Result
<Goal
<Self>, E
>>,
529 ) -> Result
<Self::InternedGoals
, E
>;
531 /// Lookup the `GoalsData` that was interned to create a `InternedGoals`.
532 fn goals_data(self, goals
: &Self::InternedGoals
) -> &[Goal
<Self>];
534 /// Create an "interned" substitution from `data`. This is not
535 /// normally invoked directly; instead, you invoke
536 /// `SubstitutionData::intern` (which will ultimately call this
538 fn intern_substitution
<E
>(
540 data
: impl IntoIterator
<Item
= Result
<GenericArg
<Self>, E
>>,
541 ) -> Result
<Self::InternedSubstitution
, E
>;
543 /// Lookup the `SubstitutionData` that was interned to create a `InternedSubstitution`.
544 fn substitution_data(self, substitution
: &Self::InternedSubstitution
) -> &[GenericArg
<Self>];
546 /// Create an "interned" program clause from `data`. This is not
547 /// normally invoked directly; instead, you invoke
548 /// `ProgramClauseData::intern` (which will ultimately call this
550 fn intern_program_clause(self, data
: ProgramClauseData
<Self>) -> Self::InternedProgramClause
;
552 /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`.
553 fn program_clause_data(self, clause
: &Self::InternedProgramClause
) -> &ProgramClauseData
<Self>;
555 /// Create an "interned" program clauses from `data`. This is not
556 /// normally invoked directly; instead, you invoke
557 /// `ProgramClauses::from_iter` (which will ultimately call this
559 fn intern_program_clauses
<E
>(
561 data
: impl IntoIterator
<Item
= Result
<ProgramClause
<Self>, E
>>,
562 ) -> Result
<Self::InternedProgramClauses
, E
>;
564 /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`.
565 fn program_clauses_data(self, clauses
: &Self::InternedProgramClauses
)
566 -> &[ProgramClause
<Self>];
568 /// Create an "interned" quantified where clauses from `data`. This is not
569 /// normally invoked directly; instead, you invoke
570 /// `QuantifiedWhereClauses::from_iter` (which will ultimately call this
572 fn intern_quantified_where_clauses
<E
>(
574 data
: impl IntoIterator
<Item
= Result
<QuantifiedWhereClause
<Self>, E
>>,
575 ) -> Result
<Self::InternedQuantifiedWhereClauses
, E
>;
577 /// Lookup the slice of `QuantifiedWhereClause` that was interned to
578 /// create a `QuantifiedWhereClauses`.
579 fn quantified_where_clauses_data(
581 clauses
: &Self::InternedQuantifiedWhereClauses
,
582 ) -> &[QuantifiedWhereClause
<Self>];
584 /// Create an "interned" parameter kinds from `data`. This is not
585 /// normally invoked directly; instead, you invoke
586 /// `VariableKinds::from_iter` (which will ultimately call this
588 fn intern_generic_arg_kinds
<E
>(
590 data
: impl IntoIterator
<Item
= Result
<VariableKind
<Self>, E
>>,
591 ) -> Result
<Self::InternedVariableKinds
, E
>;
593 /// Lookup the slice of `VariableKinds` that was interned to
594 /// create a `VariableKinds`.
595 fn variable_kinds_data(
597 variable_kinds
: &Self::InternedVariableKinds
,
598 ) -> &[VariableKind
<Self>];
600 /// Create "interned" variable kinds with universe index from `data`. This is not
601 /// normally invoked directly; instead, you invoke
602 /// `CanonicalVarKinds::from_iter` (which will ultimately call this
604 fn intern_canonical_var_kinds
<E
>(
606 data
: impl IntoIterator
<Item
= Result
<CanonicalVarKind
<Self>, E
>>,
607 ) -> Result
<Self::InternedCanonicalVarKinds
, E
>;
609 /// Lookup the slice of `CanonicalVariableKind` that was interned to
610 /// create a `CanonicalVariableKinds`.
611 fn canonical_var_kinds_data(
613 canonical_var_kinds
: &Self::InternedCanonicalVarKinds
,
614 ) -> &[CanonicalVarKind
<Self>];
616 /// Create "interned" constraints from `data`. This is not
617 /// normally invoked dirctly; instead, you invoke
618 /// `Constraints::from_iter` (which will ultimately call this
620 fn intern_constraints
<E
>(
622 data
: impl IntoIterator
<Item
= Result
<InEnvironment
<Constraint
<Self>>, E
>>,
623 ) -> Result
<Self::InternedConstraints
, E
>;
625 /// Lookup the slice of `Constraint` that was interned to
626 /// create a `Constraints`.
629 constraints
: &Self::InternedConstraints
,
630 ) -> &[InEnvironment
<Constraint
<Self>>];
632 /// Create "interned" variances from `data`. This is not
633 /// normally invoked directly; instead, you invoke
634 /// `Variances::from` (which will ultimately call this
636 fn intern_variances
<E
>(
638 data
: impl IntoIterator
<Item
= Result
<Variance
, E
>>,
639 ) -> Result
<Self::InternedVariances
, E
>;
641 /// Lookup the slice of `Variance` that was interned to
642 /// create a `Variances`.
643 fn variances_data(self, variances
: &Self::InternedVariances
) -> &[Variance
];
646 /// Implemented by types that have an associated interner (which
647 /// are virtually all of the types in chalk-ir, for example).
648 /// This lets us map from a type like `Ty<I>` to the parameter `I`.
650 /// It's particularly useful for writing `Fold` impls for generic types like
651 /// `Binder<T>`, since it allows us to figure out the interner of `T`.
652 pub trait HasInterner
{
653 /// The interner associated with the type.
654 type Interner
: Interner
;
657 impl<T
: HasInterner
> HasInterner
for [T
] {
658 type Interner
= T
::Interner
;
661 impl<T
: HasInterner
> HasInterner
for Vec
<T
> {
662 type Interner
= T
::Interner
;
665 impl<T
: HasInterner
> HasInterner
for Box
<T
> {
666 type Interner
= T
::Interner
;
669 impl<T
: HasInterner
> HasInterner
for Arc
<T
> {
670 type Interner
= T
::Interner
;
673 impl<T
: HasInterner
+ ?Sized
> HasInterner
for &T
{
674 type Interner
= T
::Interner
;
677 impl<I
: Interner
> HasInterner
for PhantomData
<I
> {
681 impl<A
, B
, I
> HasInterner
for (A
, B
)
683 A
: HasInterner
<Interner
= I
>,
684 B
: HasInterner
<Interner
= I
>,
690 impl<A
, B
, C
, I
> HasInterner
for (A
, B
, C
)
692 A
: HasInterner
<Interner
= I
>,
693 B
: HasInterner
<Interner
= I
>,
694 C
: HasInterner
<Interner
= I
>,
700 impl<'a
, T
: HasInterner
> HasInterner
for std
::slice
::Iter
<'a
, T
> {
701 type Interner
= T
::Interner
;