Type_length_limit attribute behavior

What reference says about the attribute:

The type_length_limit attribute limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. It is applied at the crate level, and uses the MetaNameValueStr syntax to set the limit based on the number of type substitutions.

#![type_length_limit = "4"]

fn f<T>(x: T) {}

// This fails to compile because monomorphizing to
// `f::<((((i32,), i32), i32), i32)>` requires more than 4 type elements.
f(((((1,), 2), 3), 4));

My question:
Is this code example correct? In my mind, there's only one instance of the function after monomorphization (f::<((((i32,), i32), i32), i32)>) and it fails to compile because the limit is too low to even compile empty main function.

It's not how many functions can be produced from one generic function, it's how deeply nested generics can be.

T 
-> (A, B)
-> ((C, D), i32)
-> (((E, F), i32), i32)
-> ((((G,), i32), i32), i32)
-> ((((i32,), i32), i32), i32)

These are the 5 substitutions.

I've never seen anyone even mention this attribute, probably because 1 million is an incredibly high limit, and the type solver usually recognizes infinite types as being infinite.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.