Skip to content

Commit

Permalink
Rollup merge of rust-lang#54781 - phansch:master, r=varkor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pietroalbini authored Oct 5, 2018
2 parents 5efac03 + 769b383 commit 9e8f522
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 9e8f522

Please sign in to comment.