Skip to content

Add examples to TyKind::FnDef and TyKind::FnPtr docs #54781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,26 @@ pub enum TyKind<'tcx> {

/// The anonymous type of a function declaration/definition. Each
/// function has a unique type.
Copy link
Member

@varkor varkor Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you could also clarify the output syntax here.

/// The anonymous type of a function declaration/definition. Each
/// 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:
///
/// ```rust
/// fn foo() -> i32 { 1 }
///
/// fn hello() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get away with just writing it on two lines, which saves a little space:

fn foo() -> i32 { 1 }
let bar = foo; // bar: fn() -> i32 {foo}

/// 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`.
Expand Down