Skip to content

Commit e9bc069

Browse files
committed
document each of the Ty variants
1 parent 63d5dad commit e9bc069

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

chalk-ir/src/lib.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,45 @@ pub enum TypeSort {
225225

226226
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
227227
pub enum Ty {
228+
/// An "application" type is one that applies the set of type
229+
/// arguments to some base type. For example, `Vec<u32>` would be
230+
/// "applying" the parameters `[u32]` to the code type `Vec`.
231+
/// This type is also used for base types like `u32` (which just apply
232+
/// an empty list).
228233
Apply(ApplicationTy),
234+
235+
/// A "projection" type corresponds to an (unnormalized)
236+
/// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the
237+
/// trait and all its parameters are fully known.
229238
Projection(ProjectionTy),
239+
240+
/// This is a variant of a projection in which the trait is
241+
/// **not** known. It corresponds to a case where people write
242+
/// `T::Item` without specifying the trait. We would then try to
243+
/// figure out the trait by looking at all the traits that are in
244+
/// scope.
230245
UnselectedProjection(UnselectedProjectionTy),
246+
247+
/// A "higher-ranked" type. In the Rust surface syntax, this can
248+
/// only be a funtion type (e.g., `for<'a> fn(&'a u32)`) or a dyn
249+
/// type (e.g., `dyn for<'a> SomeTrait<&'a u32>`). However, in
250+
/// Chalk's representation, we separate out the `for<'a>` part
251+
/// from the underlying type, so technically we can represent
252+
/// things like `for<'a> SomeStruct<'a>`, although that has no
253+
/// meaning in Rust.
231254
ForAll(Box<QuantifiedTy>),
232255

233-
/// References the binding at the given depth (deBruijn index
234-
/// style).
256+
/// References the binding at the given depth. The index is a [de
257+
/// Bruijn index], so it counts back through the in-scope biners,
258+
/// with 0 being the innermost binder. This is used in impls and
259+
/// the like. For example, if we had a rule like `for<T> { (T:
260+
/// Clone) :- (T: Copy) }`, then `T` would be represented as a
261+
/// `BoundVar(0)` (as the `for` is the innermost binder).
262+
///
263+
/// [de Bruijn index]: https://en.wikipedia.org/wiki/De_Bruijn_index
235264
BoundVar(usize),
236265

237-
/// Inference variable.
266+
/// Inference variable defined in the current inference context.
238267
InferenceVar(InferenceVar),
239268
}
240269

0 commit comments

Comments
 (0)