From 2ad74b658df566be7cef2b3b3a65d9c02ec26657 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:18:39 -0700 Subject: [PATCH 1/5] 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 bb88b872d..32521af96 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 12ad17ae41146ba34cf98b6e50e9d7ab586c674c Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:19:39 -0700 Subject: [PATCH 2/5] 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 32521af96..85383207a 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 8157052da879357bcc1a328eab3959838a832e2b Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:20:15 -0700 Subject: [PATCH 3/5] 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 85383207a..962d677ce 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 4b528d2dbbb198157ebb66119ef9eac2d8270350 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Jun 2025 15:25:31 -0700 Subject: [PATCH 4/5] 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 962d677ce..6564e1163 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] From 7d0c3c829472ae7c72a2b13da4659945dd9416da Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 22 Sep 2025 13:29:18 -0700 Subject: [PATCH 5/5] Minor update of `recursion_limit` More closely align with the template, and some minor word tweaks. --- src/attributes/limits.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/attributes/limits.md b/src/attributes/limits.md index 6564e1163..b3e8e0373 100644 --- a/src/attributes/limits.md +++ b/src/attributes/limits.md @@ -3,6 +3,7 @@ r[attributes.limits] The following [attributes] affect compile-time limits. + r[attributes.limits.recursion_limit] ## The `recursion_limit` attribute @@ -43,13 +44,13 @@ 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. +> `rustc` ignores use in other positions but lints against it. This may become an error 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. +Only the first use of `recursion_limit` on an item has effect. > [!NOTE] -> `rustc` currently warns on following duplicate `recursion_limit` attributes. This may become an error in the future. +> `rustc` lints against any use following the first. This may become an error in the future. r[attributes.limits.type_length_limit]