# Implicit generics

**URL:** <https://internals.rust-lang.org/t/implicit-generics/21311>\
**Category:** language design\
**Created:** [August 3, 2024, 12:58pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311 "2024-08-03T12:58:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ddystopia](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ddystopia/32/10915_2.png) [@Ddystopia](https://internals.rust-lang.org/u/Ddystopia)\
**Post date:** [August 3, 2024, 12:58pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311/1 "2024-08-03T12:58:12Z")

</div>

Hello, is there some RFC out there to allow implicit generics? It is quite often that I don't need named type, but I am still forced to write it. And we already have some kind of it with `impl`, but not there.

```rust
trait Foo<T>{}

fn foo(foo: impl Foo<_>) { }

```

---

<div class="post-metadata">

**Author:** ![tema2](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tema2/32/6498_2.png) [@tema2](https://internals.rust-lang.org/u/tema2)\
**Post date:** [August 3, 2024, 2:06pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311/2 "2024-08-03T14:06:55Z")

</div>

there isn't.

the thing is that if you don't care for generic on trait `Foo` then it shouldn't have it in the first place

---

<div class="post-metadata">

**Author:** ![Ddystopia](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/ddystopia/32/10915_2.png) [@Ddystopia](https://internals.rust-lang.org/u/Ddystopia)\
**Post date:** [August 3, 2024, 2:08pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311/3 "2024-08-03T14:08:35Z")

</div>

I agree, but sometimes you need it. Example: [frunk\_example](https://docs.rs/frunk/latest/frunk/path/index.html)

In that example `HeightIdx` and `UnitIdx` are generics that you can't omit from the trait and must write in the bounds, while logic doesn't really require those generics to be named.

---

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [August 3, 2024, 8:22pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311/4 "2024-08-03T20:22:33Z")

</div>

Metaprogramming like frunk does is sort of a special case; most code won't use extra type inference variables the way that frunk does. But also, at least in theory, the example signature there _could_ also be written as

```rust
fn print_height<'a, A>(obj: &'a A) -> String
where
    &'a A: PathTraverser<Path!(dimensions.height), impl Sized, TargetValue = &'a usize>
        + PathTraverser<Path!(dimensions.unit), impl Sized, TargetValue = &'a SizeUnit>,

```

except that `impl Trait` isn't permitted in this position because it's very unclear whether this is a "universal" type variable (chosen by the caller, implementation must work for any possible choice) or an "existential" type variable (chosen by the implementation, caller must work for any\[1\] possible choice).

The more specific case of your example

```rust
fn foo(foo: impl Foo<impl Sized>)

```

which is "nested `impl Trait`" rather than "`impl Trait` in bounds" might be made permissable in the future, since it's less unclear which direction the `impl` will make opaque, but that's still a good ways off. IIRC, a main question is handling `impl Fn() -> impl Trait`, as it _isn't_ clear how return position inside argument position impl trait ("RPIAPIT" 🙃) should behave\[1:1\], and to the type system that's just an associated type equality bound (i.e. `impl Fn<(), Output=impl Trait>`).

There's also [a different thread](https://internals.rust-lang.org/t/allow-in-impl-blocks-when-the-generic-arugment-doesnt-matter/21300) currently open about using `_` as a kind of minimally bound type hole in a signature, which could be somewhat related to the desire here.

* * *

1. The answer is probably that it should be an associated type trait bound (e.g. perhaps `impl Fn<(), Output: Trait>`) rather than an equality bound, but defining a composable definition of _why_ that's the desugar is far from straightforward.

---

<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:** [November 1, 2024, 8:23pm UTC](https://internals.rust-lang.org/t/implicit-generics/21311/5 "2024-11-01T20:23:20Z")

</div>

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