Is it a bad sign to have the 'reached the type-length limit' error while working with futures?


I got this error from time to time in projets using futures. I just add the type_length_limit attribute and call it a day but I’m wondering if it should be avoided.

error: reached the type-length limit while instantiating `std::sync::Once::call_once::<[closure@DefId(44/1:587 ~ futures[b...`
  = note: consider adding a `#![type_length_limit="2097152"]` attribute to your crate


I’d examine your design. It sounds like you might be doing too much of having a future, that returns a future, that returns a future, …

My guess is your’e doing something akin to infinite recursive function calls.

EDIT: I think I might be right. This might be relevant:


Avoiding an error message with long types is good for reading sanity. impl Trait to the rescue.


I’d love to see what the actual code looks like :slight_smile:


Doesn’t impl Trait make it easier to create such monsters? The full type is still created, just behind the scenes where you never have to write it.

You can break it up with dyn Trait though.