Skip to content

Commit a82fc86

Browse files
nikomatsakisKiChjang
authored andcommitted
add some comments about meaning of the binder
1 parent 3118532 commit a82fc86

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

chalk-ir/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,35 @@ pub enum Ty {
239239
/// In the chalk parser, the traits that the object represents is parsed as
240240
/// a QuantifiedInlineBound, and is then changed to a list of where clauses
241241
/// during lowering.
242+
///
243+
/// See the `Opaque` variant for a discussion about the use of
244+
/// binders here.
242245
Dyn(Binders<Vec<QuantifiedWhereClause>>),
243246

244247
/// An "opaque" type is one that is created via the "impl Trait" syntax.
245248
/// They are named so because the concrete type implementing the trait
246249
/// is unknown, and hence the type is opaque to us. The only information
247250
/// that we know of is that this type implements the traits listed by the
248251
/// user.
252+
///
253+
/// The "binder" here represents the unknown self type. So, a type like
254+
/// `impl for<'a> Fn(&'a u32)` would be represented with two-levels of
255+
/// binder, as "depicted" here:
256+
///
257+
/// ```
258+
/// exists<type> {
259+
/// vec![
260+
/// // A QuantifiedWhereClause:
261+
/// forall<region> { ^1: Fn(&^2 u32) }
262+
/// ]
263+
/// }
264+
/// ```
265+
///
266+
/// The outer `exists<type>` binder indicates that there exists
267+
/// some type that meets the criteria within, but that type is not
268+
/// known. It is referenced within the type using `^1`, indicating
269+
/// a bound type with debruijn index 1 (i.e., skipping through one
270+
/// level of binder).
249271
Opaque(Binders<Vec<QuantifiedWhereClause>>),
250272

251273
/// A "projection" type corresponds to an (unnormalized)

0 commit comments

Comments
 (0)