@@ -4,11 +4,55 @@ The following [attributes] affect compile-time limits.
4
4
5
5
## The ` recursion_limit ` attribute
6
6
7
- The * ` recursion_limit ` attribute* may be applied at the crate level to set the
7
+ The * ` recursion_limit ` attribute* may be applied at the [ crate] level to set the
8
8
maximum depth for potentially infinitely-recursive compile-time operations
9
- like auto-dereference or macro expansion. It uses the [ _ MetaNameValueStr_ ]
10
- syntax to specify the recursion depth. The default is
11
- ` #![recursion_limit="64"] ` .
9
+ like macro expansion or auto-dereference. It uses the [ _ MetaNameValueStr_ ]
10
+ syntax to specify the recursion depth.
11
+
12
+ > Note: The default in ` rustc ` is 64.
13
+
14
+ ``` rust,compile_fail
15
+ #![recursion_limit = "4"]
16
+
17
+ macro_rules! a {
18
+ () => { a!(1) };
19
+ (1) => { a!(2) };
20
+ (2) => { a!(3) };
21
+ (3) => { a!(4) };
22
+ (4) => { };
23
+ }
24
+
25
+ // This fails to expand because it requires a recursion depth greater than 4.
26
+ a!{}
27
+ ```
28
+
29
+ ``` rust,compile_fail
30
+ #![recursion_limit = "1"]
31
+
32
+ // This fails because it requires two recursive steps to auto-derefence.
33
+ (|_: &u8| {})(&&1);
34
+ ```
35
+
36
+ ## The ` type_length_limit ` attribute
37
+
38
+ The * ` type_length_limit ` attribute* limits the maximum number of type
39
+ substitutions made when constructing a concrete type during monomorphization.
40
+ It is applied at the [ crate] level, and uses the [ _ MetaNameValueStr_ ] syntax
41
+ to set the limit based on the number of type substitutions.
42
+
43
+ > Note: The default in ` rustc ` is 1048576.
44
+
45
+ ``` rust,compile_fail
46
+ #![type_length_limit = "8"]
47
+
48
+ fn f<T>(x: T) {}
49
+
50
+ // This fails to compile because monomorphizing to
51
+ // `f::<(i32, i32, i32, i32, i32, i32, i32, i32, i32)>>` requires more
52
+ // than 8 type elements.
53
+ f(((1, 2, 3, 4, 5, 6, 7, 8, 9));
54
+ ```
12
55
13
- [ attributes ] : attributes.html
14
56
[ _MetaNameValueStr_ ] : attributes.html#meta-item-attribute-syntax
57
+ [ attributes ] : attributes.html
58
+ [ crate ] : crates-and-source-files.html
0 commit comments