|
| 1 | +{ |
| 2 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4", |
| 3 | + "repository_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines", |
| 4 | + "labels_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/labels{/name}", |
| 5 | + "comments_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/comments", |
| 6 | + "events_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/events", |
| 7 | + "html_url": "https://github.com/rustfoundation/safety-critical-rust-coding-guidelines/issues/4", |
| 8 | + "id": 3104390263, |
| 9 | + "node_id": "I_kwDOOMMjbs65CTx3", |
| 10 | + "number": 4, |
| 11 | + "title": "[Coding Guideline]: testtt", |
| 12 | + "user": { |
| 13 | + "login": "rustfoundation", |
| 14 | + "id": 14003018, |
| 15 | + "node_id": "MDQ6VXNlcjE0MDAzMDE4", |
| 16 | + "avatar_url": "https://avatars.githubusercontent.com/u/14003018?v=4", |
| 17 | + "gravatar_id": "", |
| 18 | + "url": "https://api.github.com/users/rustfoundation", |
| 19 | + "html_url": "https://github.com/rustfoundation", |
| 20 | + "followers_url": "https://api.github.com/users/rustfoundation/followers", |
| 21 | + "following_url": "https://api.github.com/users/rustfoundation/following{/other_user}", |
| 22 | + "gists_url": "https://api.github.com/users/rustfoundation/gists{/gist_id}", |
| 23 | + "starred_url": "https://api.github.com/users/rustfoundation/starred{/owner}{/repo}", |
| 24 | + "subscriptions_url": "https://api.github.com/users/rustfoundation/subscriptions", |
| 25 | + "organizations_url": "https://api.github.com/users/rustfoundation/orgs", |
| 26 | + "repos_url": "https://api.github.com/users/rustfoundation/repos", |
| 27 | + "events_url": "https://api.github.com/users/rustfoundation/events{/privacy}", |
| 28 | + "received_events_url": "https://api.github.com/users/rustfoundation/received_events", |
| 29 | + "type": "User", |
| 30 | + "user_view_type": "public", |
| 31 | + "site_admin": false |
| 32 | + }, |
| 33 | + "labels": [ |
| 34 | + { |
| 35 | + "id": 8703664686, |
| 36 | + "node_id": "LA_kwDOOMMjbs8AAAACBsdiLg", |
| 37 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/category:%20advisory", |
| 38 | + "name": "category: advisory", |
| 39 | + "color": "ededed", |
| 40 | + "default": false, |
| 41 | + "description": null |
| 42 | + }, |
| 43 | + { |
| 44 | + "id": 8703664688, |
| 45 | + "node_id": "LA_kwDOOMMjbs8AAAACBsdiMA", |
| 46 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/status:%20draft", |
| 47 | + "name": "status: draft", |
| 48 | + "color": "ededed", |
| 49 | + "default": false, |
| 50 | + "description": null |
| 51 | + }, |
| 52 | + { |
| 53 | + "id": 8703664689, |
| 54 | + "node_id": "LA_kwDOOMMjbs8AAAACBsdiMQ", |
| 55 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/decidability:%20decidable", |
| 56 | + "name": "decidability: decidable", |
| 57 | + "color": "ededed", |
| 58 | + "default": false, |
| 59 | + "description": null |
| 60 | + }, |
| 61 | + { |
| 62 | + "id": 8703686409, |
| 63 | + "node_id": "LA_kwDOOMMjbs8AAAACBse3CQ", |
| 64 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/chapter:%20concurrency", |
| 65 | + "name": "chapter: concurrency", |
| 66 | + "color": "ededed", |
| 67 | + "default": false, |
| 68 | + "description": null |
| 69 | + }, |
| 70 | + { |
| 71 | + "id": 8703686412, |
| 72 | + "node_id": "LA_kwDOOMMjbs8AAAACBse3DA", |
| 73 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/scope:%20crate", |
| 74 | + "name": "scope: crate", |
| 75 | + "color": "ededed", |
| 76 | + "default": false, |
| 77 | + "description": null |
| 78 | + }, |
| 79 | + { |
| 80 | + "id": 8703732885, |
| 81 | + "node_id": "LA_kwDOOMMjbs8AAAACBshslQ", |
| 82 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/labels/accepted", |
| 83 | + "name": "accepted", |
| 84 | + "color": "6AABE8", |
| 85 | + "default": false, |
| 86 | + "description": "" |
| 87 | + } |
| 88 | + ], |
| 89 | + "state": "open", |
| 90 | + "locked": false, |
| 91 | + "assignee": null, |
| 92 | + "assignees": [ |
| 93 | + |
| 94 | + ], |
| 95 | + "milestone": null, |
| 96 | + "comments": 0, |
| 97 | + "created_at": "2025-05-30T22:24:07Z", |
| 98 | + "updated_at": "2025-05-30T22:48:17Z", |
| 99 | + "closed_at": null, |
| 100 | + "author_association": "OWNER", |
| 101 | + "active_lock_reason": null, |
| 102 | + "sub_issues_summary": { |
| 103 | + "total": 0, |
| 104 | + "completed": 0, |
| 105 | + "percent_completed": 0 |
| 106 | + }, |
| 107 | + "body": "### Chapter\n\nAssociated Items\n\n### Guideline Title\n\nRecursive function are not allowed\n\n### Category\n\nRequired\n\n### Status\n\nDraft\n\n### Release Begin\n\n1.3.0\n\n### Release End\n\nlatest\n\n### FLS Paragraph ID\n\nfls_vjgkg8kfi93\n\n### Decidability\n\nUndecidable\n\n### Scope\n\nSystem\n\n### Tags\n\nreduce-human-error\n\n### Amplification\n\nAny function shall not call itself directly or indirectly\n\n### Exception(s)\n\nRecursion may be permitted under the following conditions:\n- The recursion termination condition is simple, explicit, and well-defined.\n- The function calls itself directly, or with strictly limited and clearly documented indirection.\n- The maximum recursion depth is statically bounded and justified, ensuring no risk of stack overflow.\n- The rationale for using recursion, rather than iteration, is clearly documented and reviewed.\n- The code is accompanied by tests that exercise the recursion boundary conditions.\n\n### Rationale\n\nRecursive functions can easily cause stack overflows, which may result in exceptions or, in some cases, undefined behavior (typically some embedded systems). Although the Rust compiler supports [tail call optimization](https://en.wikipedia.org/wiki/Tail_call), this optimization is not guaranteed and depends on the specific implementation and function structure. There is an [open RFC to guarantee tail call optimization in the Rust compiler](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md), but this feature has not yet been stabilized. Until tail call optimization is guaranteed and stabilized, developers should avoid using recursive functions to prevent potential stack overflows and ensure program reliability.\n\n### Non-Compliant Example - Prose\n\nThe below function `concat_strings` is not complaint because it call itself and depending on depth of data provided as input it could generate an stack overflow exception or undefine behavior.\n\n### Non-Compliant Example - Code\n\n```rust\n// Recursive enum to represent a string or a list of `MyEnum`\nenum MyEnum {\n Str(String),\n List(Vec<MyEnum>),\n}\n\n// Concatenates strings from a nested structure of `MyEnum` using recursion.\nfn concat_strings(input: &[MyEnum]) -> String {\n let mut result = String::new();\n for item in input {\n match item {\n MyEnum::Str(s) => result.push_str(s),\n MyEnum::List(list) => result.push_str(&concat_strings(list)),\n }\n }\n result\n}\n```\n\n### Compliant Example - Prose\n\nThe following code implements the same functionality using iteration instead of recursion. The `stack` variable is used to maintain the processing context at each step of the loop. This approach provides explicit control over memory usage. If the stack grows beyond a predefined limit due to the structure or size of the input, the function returns an error rather than risking a stack overflow or out-of-memory exception. This ensures more predictable and robust behavior in resource-constrained environments.\n\n### Compliant Example - Code\n\n```rust\n// Recursive enum to represent a string or a list of `MyEnum`\nenum MyEnum {\n Str(String),\n List(Vec<MyEnum>),\n}\n\n/// Concatenates strings from a nested structure of `MyEnum` without using recursion.\n/// Returns an error if the stack size exceeds `MAX_STACK_SIZE`.\nfn concat_strings_non_recursive(input: &[MyEnum]) -> Result<String, &'static str> {\n const MAX_STACK_SIZE: usize = 1000;\n let mut result = String::new();\n let mut stack = Vec::new();\n\n // Add all items to the stack\n stack.extend(input.iter());\n\n while let Some(item) = stack.pop() {\n match item {\n MyEnum::Str(s) => result.insert_str(0, s),\n MyEnum::List(list) => {\n // Add list items to the stack\n for sub_item in list.iter() {\n stack.push(sub_item);\n if stack.len() > MAX_STACK_SIZE {\n return Err(\"Too big structure\");\n }\n }\n }\n }\n }\n Ok(result)\n}\n```", |
| 108 | + "closed_by": null, |
| 109 | + "reactions": { |
| 110 | + "url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/reactions", |
| 111 | + "total_count": 0, |
| 112 | + "+1": 0, |
| 113 | + "-1": 0, |
| 114 | + "laugh": 0, |
| 115 | + "hooray": 0, |
| 116 | + "confused": 0, |
| 117 | + "heart": 0, |
| 118 | + "rocket": 0, |
| 119 | + "eyes": 0 |
| 120 | + }, |
| 121 | + "timeline_url": "https://api.github.com/repos/rustfoundation/safety-critical-rust-coding-guidelines/issues/4/timeline", |
| 122 | + "performed_via_github_app": null, |
| 123 | + "state_reason": null |
| 124 | +} |
0 commit comments