From 4d58821eee014c231c7a8d4802c3f221bbe14890 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Wed, 3 Oct 2018 13:24:44 +0200 Subject: [PATCH 1/2] Add examples to `TyKind::FnDef` and `TyKind::FnPtr` docs --- src/librustc/ty/sty.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 8e4819b68a95f..4cf4668443fb2 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -127,9 +127,26 @@ pub enum TyKind<'tcx> { /// The anonymous type of a function declaration/definition. Each /// function has a unique type. + /// + /// For example the type of `a` here: + /// + /// ```rust + /// fn foo() -> i32 { 1 } + /// + /// fn hello() { + /// let a = foo; + /// } + /// ``` FnDef(DefId, &'tcx Substs<'tcx>), /// A pointer to a function. Written as `fn() -> i32`. + /// + /// For example the type of `a` here: + /// + /// ```rust + /// fn foo() -> i32 { 1 } + /// let a: fn() -> i32 = foo; + /// ``` FnPtr(PolyFnSig<'tcx>), /// A trait, defined with `trait`. From 769b3832fd984a865358de43dc594d9333193558 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Thu, 4 Oct 2018 20:27:53 +0200 Subject: [PATCH 2/2] Further improve docs for `FnDef` and `FnPtr` --- src/librustc/ty/sty.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 4cf4668443fb2..90e3f595152de 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -126,26 +126,24 @@ 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 `a` here: + /// For example the type of `bar` here: /// /// ```rust /// fn foo() -> i32 { 1 } - /// - /// fn hello() { - /// let a = foo; - /// } + /// 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 `a` here: + /// For example the type of `bar` here: /// /// ```rust /// fn foo() -> i32 { 1 } - /// let a: fn() -> i32 = foo; + /// let bar: fn() -> i32 = foo; /// ``` FnPtr(PolyFnSig<'tcx>),