# Fn,FnOnce,FnMut with named parameters

**URL:** <https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149>\
**Category:** Uncategorized\
**Created:** [June 28, 2025, 3:51pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149 "2025-06-28T15:51:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alphapage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alphapage/32/13167_2.png) [@Alphapage](https://internals.rust-lang.org/u/Alphapage)\
**Post date:** [June 28, 2025, 3:51pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/1 "2025-06-28T15:51:36Z")

</div>

Hello,

It is impossible to add a name to Fn,FnOnce,FnMut parameters.

For example,

```rust
where Builder: FnOnce(id:i32,color:i32,quantity:i32) -> Self

```

is more expressive than

```rust
where Builder: FnOnce(i32,i32,i32) -> Self

```

Is it a crazy idea to be able to add named parameters when necessary or requested ? Maybe there is a rfc ?

Thank you in advance for your answers.

---

<div class="post-metadata">

**Author:** ![petrochenkov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/petrochenkov/32/2784_2.png) [@petrochenkov](https://internals.rust-lang.org/u/petrochenkov)\
**Post date:** [June 28, 2025, 4:37pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/2 "2025-06-28T16:37:42Z")

</div>

There's an RFC issue for this ([Naming arguments in Fn traits · Issue #2812 · rust-lang/rfcs · GitHub](https://github.com/rust-lang/rfcs/issues/2812)) and it was also recently supported in parser as an error recovery technique ([Parser: Recover error from named params while parse\_path by xizheyin · Pull Request #140671 · rust-lang/rust · GitHub](https://github.com/rust-lang/rust/pull/140671)).

---

<div class="post-metadata">

**Author:** ![Alphapage](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alphapage/32/13167_2.png) [@Alphapage](https://internals.rust-lang.org/u/Alphapage)\
**Post date:** [June 28, 2025, 5:33pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/3 "2025-06-28T17:33:23Z")

</div>

Thank you. The work is on the way then... 👍

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [June 29, 2025, 12:49am UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/4 "2025-06-29T00:49:07Z")

</div>

Just pass a single struct if you want names.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [June 29, 2025, 12:44pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/5 "2025-06-29T12:44:23Z")

</div>

I don't think anything has actually happened to that issue (note that it's not even an RFC draft, never mind an accepted RFC). Someone just created an _issue_ (not a PR) that in itself does nothing and doesn't trigger any formal process. \[1\]

The biggest problem I can see with the idea is that it's not obvious whether the parameter names are pure documentation (as proposed here) or somehow part of the function type. That is, one of the problems with named parameters in general.

* * *

1. I think it should be clarified that issues in the RFC repo should be solely to report specification bugs in accepted RFCs, and RFC proposals and feature requests should be discussed on i.r-l.o instead).

---

<div class="post-metadata">

**Author:** ![petrochenkov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/petrochenkov/32/2784_2.png) [@petrochenkov](https://internals.rust-lang.org/u/petrochenkov)\
**Post date:** [June 29, 2025, 8:26pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/6 "2025-06-29T20:26:25Z")

</div>

> [@Alphapage](#):
>
> The biggest problem I can see with the idea is that it's not obvious whether the parameter names are pure documentation (as proposed here) or somehow part of the function type.

It's pure documentation, like in function pointers right now.   
`type Foo = fn(id: i32, color: i32, quantity: i32);` is already supported.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [June 29, 2025, 9:55pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/7 "2025-06-29T21:55:32Z")

</div>

Oh, I didn't know that's permitted. In that case, it would certainly be consistent for the function trait syntax to support it too.

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/quinedot/32/7294_2.png) [@quinedot](https://internals.rust-lang.org/u/quinedot)\
**Post date:** [June 30, 2025, 2:42am UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/8 "2025-06-30T02:42:33Z")

</div>

I always viewed it as a "consistent with what" matter. You can view `dyn Fn(&str)` as inconsistent with `fn(frobber: &str)`. But if this feature request lands for types, you could view `dyn Fn(frobber: &str)` as inconsistent with `dyn Fn<(&str,)>` / other `dyn` types / the notional desugaring.\[1\]

I'm not arguing one way or the other. There are other inconsistencies in the language anyway, such as not being able to elide names in function/method signatures,\[2\] functions/methods with bodies accepting full patterns but `fn(..)` and methods without bodies not doing so, etc. All the little differences are collectively a learning speed bump with or without this feature.

* * *

1. Though the OP was about trait bounds, not types; the connection with `fn(..)` is less direct than that case. 

2. [mostly](https://github.com/rust-lang/rust/issues/41686)

---

<div class="post-metadata">

**Author:** ![toc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/toc/32/6692_2.png) [@toc](https://internals.rust-lang.org/u/toc)\
**Post date:** [June 30, 2025, 3:47pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/9 "2025-06-30T15:47:43Z")

</div>

> [@scottmcm](#):
>
> Just pass a single struct if you want names.

At present this is a little annoying, but it could be nice if rust had a little extra inference for the case. Something like

```rust
// Not sure if the struct could be anonymous but here it's foo::B
fn foo(a: i32, b: struct B {location: &Point, color: &Color, tag: &str}) { ... }

foo(7, _ {location: x, color: &CYAN, tag: "hello"});

```

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [June 30, 2025, 10:07pm UTC](https://internals.rust-lang.org/t/fn-fnonce-fnmut-with-named-parameters/23149/10 "2025-06-30T22:07:38Z")

</div>

> [@toc](#):
>
> but it could be nice if rust had a little extra inference for the case

Yup, we've had a bunch of IRLO conversations about that, and there's this proposal open: [Inferred types `_::Enum` by JoshuaBrest · Pull Request #3444 · rust-lang/rfcs · GitHub](https://github.com/rust-lang/rfcs/pull/3444)
