Rollup merge of #54781 - phansch:master, r=varkor

Add examples to `TyKind::FnDef` and `TyKind::FnPtr` docs

This adds two examples to the docs of `TyKind::FnDef` and `TyKind::FnPtr`.

I found these two types a bit confusing when I learned about them and I think adding these examples might help others.
This commit is contained in:
Pietro Albini 2018-10-05 22:33:12 +02:00 committed by GitHub
commit 9e8f522e80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 1 deletions

View File

@ -126,10 +126,25 @@ pub enum TyKind<'tcx> {
Ref(Region<'tcx>, Ty<'tcx>, hir::Mutability),
/// The anonymous type of a function declaration/definition. Each
/// function has a unique type.
/// function has a unique type, which is output (for a function
/// named `foo` returning an `i32`) as `fn() -> i32 {foo}`.
///
/// For example the type of `bar` here:
///
/// ```rust
/// fn foo() -> i32 { 1 }
/// let bar = foo; // bar: fn() -> i32 {foo}
/// ```
FnDef(DefId, &'tcx Substs<'tcx>),
/// A pointer to a function. Written as `fn() -> i32`.
///
/// For example the type of `bar` here:
///
/// ```rust
/// fn foo() -> i32 { 1 }
/// let bar: fn() -> i32 = foo;
/// ```
FnPtr(PolyFnSig<'tcx>),
/// A trait, defined with `trait`.