For now, this reference is a best-effort document. We strive for validity and completeness, but are not yet there. In the future, the docs and lang teams will work together to figure out how best to do this. Until then, this is a best-effort attempt. If you find something wrong or missing, file an issue or send in a pull request.

Limits

The following attributes affect compile-time limits.

The recursion_limit attribute

The recursion_limit attribute may be applied at the crate level to set the maximum depth for potentially infinitely-recursive compile-time operations like macro expansion or auto-dereference. It uses the MetaNameValueStr syntax to specify the recursion depth.

Note: The default in rustc is 128.


# #![allow(unused_variables)]
#![recursion_limit = "4"]

#fn main() {
macro_rules! a {
    () => { a!(1) };
    (1) => { a!(2) };
    (2) => { a!(3) };
    (3) => { a!(4) };
    (4) => { };
}

// This fails to expand because it requires a recursion depth greater than 4.
a!{}
#}

# #![allow(unused_variables)]
#![recursion_limit = "1"]

#fn main() {
// This fails because it requires two recursive steps to auto-derefence.
(|_: &u8| {})(&&1);
#}

The type_length_limit 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.

Note: The default in rustc is 1048576.

#![type_length_limit = "8"]

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

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