@@ -538,6 +538,9 @@ impl<'tcx, T: TypeVisitable<'tcx>> TypeVisitable<'tcx> for &'tcx ty::List<T> {
538
538
/// Similar to [`super::Binder`] except that it tracks early bound generics, i.e. `struct Foo<T>(T)`
539
539
/// needs `T` substituted immediately. This type primarily exists to avoid forgetting to call
540
540
/// `subst`.
541
+ ///
542
+ /// If you don't have anything to `subst`, you may be looking for
543
+ /// [`subst_identity`](EarlyBinder::subst_identity) or [`skip_binder`](EarlyBinder::skip_binder).
541
544
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash , Debug ) ]
542
545
#[ derive( Encodable , Decodable , HashStable ) ]
543
546
pub struct EarlyBinder < T > ( pub T ) ;
@@ -578,6 +581,14 @@ impl<T> EarlyBinder<T> {
578
581
EarlyBinder ( value)
579
582
}
580
583
584
+ /// Skips the binder and returns the "bound" value.
585
+ /// This can be used to extract data that does not depend on generic parameters
586
+ /// (e.g., getting the `DefId` of the inner value or getting the number of
587
+ /// arguments of an `FnSig`). Otherwise, consider using
588
+ /// [`subst_identity`](EarlyBinder::subst_identity).
589
+ ///
590
+ /// See also [`Binder::skip_binder`](super::Binder::skip_binder), which is
591
+ /// the analogous operation on [`super::Binder`].
581
592
pub fn skip_binder ( self ) -> T {
582
593
self . 0
583
594
}
@@ -729,6 +740,14 @@ impl<'tcx, T: TypeFoldable<'tcx>> ty::EarlyBinder<T> {
729
740
self . 0 . fold_with ( & mut folder)
730
741
}
731
742
743
+ /// Makes the identity substitution `T0 => T0, ..., TN => TN`.
744
+ /// Conceptually, this converts universally bound variables into placeholders
745
+ /// when inside of a given item.
746
+ ///
747
+ /// For example, consider `for<T> fn foo<T>(){ .. }`:
748
+ /// - Outside of `foo`, `T` is bound (represented by the presence of `EarlyBinder`).
749
+ /// - Inside of the body of `foo`, we treat `T` as a placeholder by calling
750
+ /// `subst_identity` to discharge the `EarlyBinder`.
732
751
pub fn subst_identity ( self ) -> T {
733
752
self . 0
734
753
}
0 commit comments