# \[Pre-RFC\] Function types

**URL:** <https://internals.rust-lang.org/t/pre-rfc-function-types/474>\
**Category:** ideas (deprecated)\
**Created:** [September 7, 2014, 10:16pm UTC](https://internals.rust-lang.org/t/pre-rfc-function-types/474 "2014-09-07T22:16:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tobba](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@Tobba](https://internals.rust-lang.org/u/Tobba)\
**Post date:** [September 7, 2014, 10:16pm UTC](https://internals.rust-lang.org/t/pre-rfc-function-types/474/1 "2014-09-07T22:16:17Z")

</div>

# Summary

Currently, each unboxed closure definition generates its own unique type, functions however do not exhibit the same behavior. This RFC proposes the addition of a unique compiler-generated zero-sized anonymous type for each function definition.

# Motivation

This allows a normal function to be used in place where any unboxed closure would, with the exact same generated code as if the function was an unboxed closure with no captures. As it stands the function would instead be passed as a pointer, which leads to pointless indirection and missed optimizations.

As this causes a function to be equivalent (bar the coercions to `fn()` and calling syntax) to a struct with no fields implementing `Fn`, `FnMut` and `FnOnce`, it may lead to further simplification of the language and the compiler.

# Detailed design

Each function shall have its own anonymous, zero-sized type, henceforth referred to as a “function type”. Each function type should implement `Fn`, `FnMut` and `FnOnce`. Any reference of a function as a literal should result in the instantiation of that functions associated type. Every function type should also be coercible to an appropriate `fn()` type.

# Drawbacks

The superfluous type information may lead to slowdowns during compilation. This is also introduces extra coercion rules which may be undesirable.

# Alternatives

None currently proposed.

# Unresolved questions

None.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:22am UTC](https://internals.rust-lang.org/t/pre-rfc-function-types/474/2 "2019-03-25T08:22:51Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
