Skip to content

Commit f46e1df

Browse files
committed
Document type_length_limit.
1 parent be09d08 commit f46e1df

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/attributes.md

+2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ The following is an index of all built-in attributes.
227227
- Limits
228228
- [`recursion_limit`] — Sets the maximum recursion limit for certain
229229
compile-time operations.
230+
- [`type_length_limit`] — Sets the maximum size of a polymorphic type.
230231
- Runtime
231232
- [`panic_handler`] — Sets the function to handle panics.
232233
- [`global_allocator`] — Sets the global memory allocator.
@@ -283,6 +284,7 @@ The following is an index of all built-in attributes.
283284
[`repr`]: type-layout.html#representations
284285
[`should_panic`]: attributes/testing.html#the-should_panic-attribute
285286
[`test`]: attributes/testing.html#the-test-attribute
287+
[`type_length_limit`]: attributes/limits.html#the-type_length_limit-attribute
286288
[`used`]: abi.html#the-used-attribute
287289
[`warn`]: attributes/diagnostics.html#lint-check-attributes
288290
[`windows_subsystem`]: runtime.html#the-windows_subsystem-attribute

src/attributes/limits.md

+36-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,42 @@ The following [attributes] affect compile-time limits.
77
The *`recursion_limit` attribute* may be applied at the crate level to set the
88
maximum depth for potentially infinitely-recursive compile-time operations
99
like auto-dereference or macro expansion. It uses the [_MetaNameValueStr_]
10-
syntax to specify the recursion depth. The default is
11-
`#![recursion_limit="64"]`.
10+
syntax to specify the recursion depth. The default is 64.
11+
12+
```rust,ignore
13+
#![recursion_limit = "4"]
14+
15+
macro_rules! a {
16+
() => { a!(1) };
17+
(1) => { a!(2) };
18+
(2) => { a!(3) };
19+
(3) => { a!(4) };
20+
(4) => { };
21+
}
22+
23+
// This fails to expand because it requires a recursion depth greater than 4.
24+
a!{}
25+
```
26+
27+
## The `type_length_limit` attribute
28+
29+
The *`type_length_limit` attribute* limits the maximum size of a type
30+
constructed during monomorphization. It is applied at the crate level, and
31+
uses the [_MetaNameValueStr_] syntax to set the limit based on the number of
32+
type substitutions within the type. The default value is 1048576.
33+
34+
```rust,ignore
35+
#![type_length_limit = "8"]
36+
37+
type A = (B, B, B);
38+
type B = (C, C, C);
39+
struct C;
40+
41+
// This fails to compile because monomorphizing to
42+
// `drop::<Option<((C, C, C), (C, C, C), (C, C, C))>>` requires more than 8
43+
// type elements.
44+
drop::<Option<A>>(None);
45+
```
1246

1347
[attributes]: attributes.html
1448
[_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax

0 commit comments

Comments
 (0)