Skip to content

Commit 3013b84

Browse files
ehusstraviscross
authored andcommitted
Move type_length_limit example to the intro
1 parent ae8f836 commit 3013b84

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/attributes/limits.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,23 @@ r[attributes.limits.type_length_limit]
5151
r[attributes.limits.type_length_limit.intro]
5252
The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization.
5353

54+
> [!EXAMPLE]
55+
> <!-- ignore: not enforced without nightly flag -->
56+
> ```rust,ignore
57+
> #![type_length_limit = "4"]
58+
>
59+
> fn f<T>(x: T) {}
60+
>
61+
> // This fails to compile because monomorphizing to
62+
> // `f::<((((i32,), i32), i32), i32)>` requires more than 4 type elements.
63+
> f(((((1,), 2), 3), 4));
64+
> ```
65+
5466
r[attributes.limits.type_length_limit.syntax]
5567
It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax to set the limit based on the number of type substitutions.
5668
5769
> [!NOTE]
5870
> The default in `rustc` is 1048576.
5971
60-
```rust,ignore
61-
#![type_length_limit = "4"]
62-
63-
fn f<T>(x: T) {}
64-
65-
// This fails to compile because monomorphizing to
66-
// `f::<((((i32,), i32), i32), i32)>` requires more than 4 type elements.
67-
f(((((1,), 2), 3), 4));
68-
```
69-
7072
[attributes]: ../attributes.md
7173
[crate]: ../crates-and-source-files.md

0 commit comments

Comments
 (0)