From a826291eec964a3d334488bd425d2b847990909a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:18:39 -0700 Subject: [PATCH 1/4] Unwrap recursion_limit --- src/attributes/limits.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 0e1543116..fe8467df2 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -7,13 +7,10 @@ r[attributes.limits.recursion_limit] ## The `recursion_limit` attribute r[attributes.limits.recursion_limit.intro] -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. +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. r[attributes.limits.recursion_limit.syntax] -It uses the [MetaNameValueStr] -syntax to specify the recursion depth. +It uses the [MetaNameValueStr] syntax to specify the recursion depth. > [!NOTE] > The default in `rustc` is 128. From 5bc89587ff9cd8183255143a4761c8bd21812b22 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:19:39 -0700 Subject: [PATCH 2/4] Move recursion_limit examples to intro and example block --- src/attributes/limits.md | 46 +++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index fe8467df2..671681818 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -9,34 +9,36 @@ r[attributes.limits.recursion_limit] r[attributes.limits.recursion_limit.intro] 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. +> [!EXAMPLE] +> ```rust,compile_fail +> #![recursion_limit = "4"] +> +> 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!{} +> ``` + +> [!EXAMPLE] +> ```rust,compile_fail +> #![recursion_limit = "1"] +> +> // This fails because it requires two recursive steps to auto-dereference. +> (|_: &u8| {})(&&&1); +> ``` + r[attributes.limits.recursion_limit.syntax] It uses the [MetaNameValueStr] syntax to specify the recursion depth. > [!NOTE] > The default in `rustc` is 128. -```rust,compile_fail -#![recursion_limit = "4"] - -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!{} -``` - -```rust,compile_fail -#![recursion_limit = "1"] - -// This fails because it requires two recursive steps to auto-dereference. -(|_: &u8| {})(&&&1); -``` - r[attributes.limits.type_length_limit] ## The `type_length_limit` attribute From eae626e565f84b95a6b2c64534cb96fdff66bb93 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:20:15 -0700 Subject: [PATCH 3/4] Move recursion_limit note to the intro --- src/attributes/limits.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 671681818..e4992062b 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -33,12 +33,12 @@ The *`recursion_limit` attribute* may be applied at the [crate] level to set the > (|_: &u8| {})(&&&1); > ``` +> [!NOTE] +> The default recursion limit in `rustc` is 128. + r[attributes.limits.recursion_limit.syntax] It uses the [MetaNameValueStr] syntax to specify the recursion depth. -> [!NOTE] -> The default in `rustc` is 128. - r[attributes.limits.type_length_limit] ## The `type_length_limit` attribute From 6556bcb49d2c81e6f0f13e0ee5a00c3eed5c785d Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:25:31 -0700 Subject: [PATCH 4/4] Update recursion_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 e4992062b..d3c4a2483 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -7,7 +7,7 @@ r[attributes.limits.recursion_limit] ## The `recursion_limit` attribute r[attributes.limits.recursion_limit.intro] -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. +The *`recursion_limit` [attribute][attributes]* sets the maximum depth for potentially infinitely-recursive compile-time operations like macro expansion or auto-dereference. > [!EXAMPLE] > ```rust,compile_fail @@ -37,7 +37,19 @@ The *`recursion_limit` attribute* may be applied at the [crate] level to set the > The default recursion limit in `rustc` is 128. r[attributes.limits.recursion_limit.syntax] -It uses the [MetaNameValueStr] syntax to specify the recursion depth. +The `recursion_limit` attribute uses the [MetaNameValueStr] syntax to specify the recursion depth. The value in the string must be a non-negative integer. + +r[attributes.limits.recursion_limit.allowed-positions] +The `recursion_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.recursion_limit.duplicates] +Only the first instance of `recursion_limit` on an item is honored. Subsequent `recursion_limit` attributes are ignored. + +> [!NOTE] +> `rustc` currently warns on following duplicate `recursion_limit` attributes. This may become an error in the future. r[attributes.limits.type_length_limit] ## The `type_length_limit` attribute