From 09ebb2ee7745a147a9e78029aa00bdc004b46146 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:26:19 -0700 Subject: [PATCH 1/4] Unwrap type_length_limit --- src/attributes/limits.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 0e1543116..197b0f3ca 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -49,12 +49,10 @@ r[attributes.limits.type_length_limit] > For more information, see . r[attributes.limits.type_length_limit.intro] -The *`type_length_limit` attribute* limits the maximum number of type -substitutions made when constructing a concrete type during monomorphization. +The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. r[attributes.limits.type_length_limit.syntax] -It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax -to set the limit based on the number of type substitutions. +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. From b83596e0924b81223cd74696989caf0544f848dd Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:28:14 -0700 Subject: [PATCH 2/4] Move type_length_limit example to the intro --- src/attributes/limits.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 197b0f3ca..890f40f3d 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -51,21 +51,23 @@ r[attributes.limits.type_length_limit] r[attributes.limits.type_length_limit.intro] The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. +> [!EXAMPLE] +> +> ```rust,ignore +> #![type_length_limit = "4"] +> +> fn f(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)); +> ``` + r[attributes.limits.type_length_limit.syntax] 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. -```rust,ignore -#![type_length_limit = "4"] - -fn f(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)); -``` - [attributes]: ../attributes.md [crate]: ../crates-and-source-files.md From 051af0512842ad4962658e85cb9d7ca06cf518ac Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:29:48 -0700 Subject: [PATCH 3/4] Move type_length_limit notes to the intro --- src/attributes/limits.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 890f40f3d..0cf1efb42 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -43,14 +43,14 @@ a!{} r[attributes.limits.type_length_limit] ## The `type_length_limit` attribute +r[attributes.limits.type_length_limit.intro] +The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. + > [!NOTE] -> This limit is only enforced when the nightly `-Zenforce-type-length-limit` flag is active. +> In `rustc` this limit is only enforced when the nightly `-Zenforce-type-length-limit` flag is active. > > For more information, see . -r[attributes.limits.type_length_limit.intro] -The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. - > [!EXAMPLE] > > ```rust,ignore @@ -63,11 +63,11 @@ The *`type_length_limit` attribute* limits the maximum number of type substituti > f(((((1,), 2), 3), 4)); > ``` -r[attributes.limits.type_length_limit.syntax] -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. +r[attributes.limits.type_length_limit.syntax] +It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax to set the limit based on the number of type substitutions. + [attributes]: ../attributes.md [crate]: ../crates-and-source-files.md From ee2bd23c1d7331d5cf56ad94a48713a9d98dc51b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:33:45 -0700 Subject: [PATCH 4/4] Update type_length_limit to use the attribute template --- src/attributes/limits.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 0cf1efb42..7a1248ef2 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -44,7 +44,7 @@ r[attributes.limits.type_length_limit] ## The `type_length_limit` attribute r[attributes.limits.type_length_limit.intro] -The *`type_length_limit` attribute* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. +The *`type_length_limit` [attribute][attributes]* limits the maximum number of type substitutions made when constructing a concrete type during monomorphization. > [!NOTE] > In `rustc` this limit is only enforced when the nightly `-Zenforce-type-length-limit` flag is active. @@ -67,7 +67,19 @@ The *`type_length_limit` attribute* limits the maximum number of type substituti > The default in `rustc` is 1048576. r[attributes.limits.type_length_limit.syntax] -It is applied at the [crate] level, and uses the [MetaNameValueStr] syntax to set the limit based on the number of type substitutions. +The `type_length_limit` attribute uses the [MetaNameValueStr] syntax to set the limit. The value in the string must be a non-negative number. + +r[attributes.limits.type_length_limit.allowed-positions] +The `type_length_limit` attribute may only be applied to the crate root. + +> [!NOTE] +> `rustc` currently warns in other positions, but this may be rejected in the future. + +r[attributes.limits.type_length_limit.duplicates] +Only the first instance of `type_length_limit` on an item is honored. Subsequent `type_length_limit` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on following duplicate `type_length_limit` attributes. This may become an error in the future. [attributes]: ../attributes.md [crate]: ../crates-and-source-files.md