# Exponentially growing impl trait type names

**URL:** <https://internals.rust-lang.org/t/exponentially-growing-impl-trait-type-names/7447>\
**Category:** compiler\
**Created:** [May 3, 2018, 11:22pm UTC](https://internals.rust-lang.org/t/exponentially-growing-impl-trait-type-names/7447 "2018-05-03T23:22:21Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![earthengine](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/earthengine/32/2577_2.png) [@earthengine](https://internals.rust-lang.org/u/earthengine)\
**Post date:** [May 4, 2018, 6:31am UTC](https://internals.rust-lang.org/t/exponentially-growing-impl-trait-type-names/7447/5 "2018-05-04T06:31:25Z")

</div>

Unfortunately, I think closure is just making thing worse, not better.

[Playground link](https://play.rust-lang.org/?gist=0cfd688174db06e712c9a615fbd5038e&version=nightly&mode=debug)

(I am a bit curious about why I have to use explicit life time for function `roll`, should it be automated?)

```rust
#![feature(core_intrinsics)]

use std::mem::size_of;

trait Reflactable {
    fn size(&self) -> usize;
    fn type_name_len(&self) -> usize;
    fn type_name(&self) -> String;
}

impl<'a,T> Reflactable for T where T:'a
{
    fn size(&self) -> usize {
        size_of::<Self>()
    }
    fn type_name_len(&self) -> usize {
        self.type_name().len()
    }
    fn type_name(&self) -> String {
        format!("{}", unsafe { std::intrinsics::type_name::<Self>() })
    }
}

enum Stuff<T1,T2>
{
    This(T1),
    That(T2)
}
use Stuff::{This,That};

struct W<F, T>
    where F:FnOnce() -> T + Sized {
    f: F        
}

fn roll<'a>(a:impl Reflactable + 'a) -> impl Reflactable + 'a {
    W{ f:|| if true {This(a)} else { That(a) } }
}

fn main() {
    let v = roll(1);
    println!("({},{})", v.size(), v.type_name_len());
    let v = roll(v);
    println!("{}",v.type_name());
    println!("({},{})", v.size(), v.type_name_len());
    let v = roll(v);
    println!("({},{})", v.size(), v.type_name_len());
    let v = roll(v);
    println!("({},{})", v.size(), v.type_name_len());
    let v = roll(v);
    println!("({},{})", v.size(), v.type_name_len());
    let v = roll(v);
    println!("({},{})", v.size(), v.type_name_len());
}

```

Output:

```nohighlight
(4,60)
W<[closure@src/main.rs:38:10: 38:47 a:W<[closure@src/main.rs:38:10: 38:47 a:i32], Stuff<i32, i32>>], Stuff<W<[closure@src/main.rs:38:10: 38:47 a:i32], Stuff<i32, i32>>, W<[closure@src/main.rs:38:10: 38:47 a:i32], Stuff<i32, i32>>>>
(4,231)
(4,744)
(4,2283)
(4,6900)
(4,20751)

```

The growth rate is even higher… and the closure didn’t hide any types within, so it didn’t resolve anything.

---

_[View the full topic](https://internals.rust-lang.org/t/exponentially-growing-impl-trait-type-names/7447)._
