Skip to content

Commit 9da846e

Browse files
x0rwgithub-actions[bot]
authored andcommitted
Add guideline for issue #21
Co-authored-by: x0rw <[email protected]>
1 parent ceae2f7 commit 9da846e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/coding-guidelines/associated-items.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,41 @@
55

66
Associated Items
77
================
8+
9+
.. guideline:: Guideline Test
10+
:id: gui_ebWvmAlAAYAl
11+
:category: advisory
12+
:status: draft
13+
:release: 1.1.1-1.1.1
14+
:fls: fls_vjgkg8kfi93
15+
:decidability: decidable
16+
:scope: module
17+
:tags: stack-overflow
18+
19+
Any function shall not call itself directly or indirectly
20+
21+
.. rationale::
22+
:id: rat_ywT9UySQo3oi
23+
:status: draft
24+
25+
Recursive 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.
26+
27+
.. non_compliant_example::
28+
:id: non_compl_ex_sFlKLx3YG3Un
29+
:status: draft
30+
31+
The 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.
32+
33+
.. code-block:: rust
34+
35+
MyEnumMyEnum
36+
37+
.. compliant_example::
38+
:id: compl_ex_5sKCv53VdydT
39+
:status: draft
40+
41+
tete
42+
43+
.. code-block:: rust
44+
45+
MyEnumMyEnumMAX_STACK_SIZE

0 commit comments

Comments
 (0)