Skip to content

Commit 9e8f522

Browse files
authored
Rollup merge of rust-lang#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.
2 parents 5efac03 + 769b383 commit 9e8f522

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/librustc/ty/sty.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,25 @@ pub enum TyKind<'tcx> {
126126
Ref(Region<'tcx>, Ty<'tcx>, hir::Mutability),
127127

128128
/// The anonymous type of a function declaration/definition. Each
129-
/// function has a unique type.
129+
/// function has a unique type, which is output (for a function
130+
/// named `foo` returning an `i32`) as `fn() -> i32 {foo}`.
131+
///
132+
/// For example the type of `bar` here:
133+
///
134+
/// ```rust
135+
/// fn foo() -> i32 { 1 }
136+
/// let bar = foo; // bar: fn() -> i32 {foo}
137+
/// ```
130138
FnDef(DefId, &'tcx Substs<'tcx>),
131139

132140
/// A pointer to a function. Written as `fn() -> i32`.
141+
///
142+
/// For example the type of `bar` here:
143+
///
144+
/// ```rust
145+
/// fn foo() -> i32 { 1 }
146+
/// let bar: fn() -> i32 = foo;
147+
/// ```
133148
FnPtr(PolyFnSig<'tcx>),
134149

135150
/// A trait, defined with `trait`.

0 commit comments

Comments
 (0)