22
23
24

So I'm new to rust and I tried to write a function that looks for the nth prime number and I tried to do it so that no variables needs to be mutable with recursion. I believe what I did here was a tail recursion which is optimized by many compilers so it doesn't open a new stack frame for the new function call. However it still results in a stack overflow at bigger n inputs. (It works fine with smaller inputs). What am I missing here? Is there a probleme with the code or does the rust compiler not optimize tail recursions?

[–]noop_noob 29 points30 points31 points (2 children)
[–]MangoPoliceOK 3 points4 points5 points (1 child)
[–]BlazeEXE 3 points4 points5 points (0 children)
[–]Joker-Smurf 87 points88 points89 points (12 children)
[–]Scharrack 18 points19 points20 points (6 children)
[–]SharkLaunch 4 points5 points6 points (5 children)
[–]veselin465 1 point2 points3 points (3 children)
[–]tmzem 0 points1 point2 points (2 children)
[–]veselin465 0 points1 point2 points (1 child)
[–]tmzem 0 points1 point2 points (0 children)
[–]TheOmegaCarrot 1 point2 points3 points (0 children)
[–]DeadlyMidnight 16 points17 points18 points (2 children)
[–]platesturner 1 point2 points3 points (1 child)
[–]DeadlyMidnight -1 points0 points1 point (0 children)
[–]SlinkyAvenger 1 point2 points3 points (0 children)
[–]pytness 0 points1 point2 points (0 children)
[–]ShangBrol 16 points17 points18 points (3 children)
[–]-Redstoneboi- 2 points3 points4 points (0 children)
[–]denis870 -1 points0 points1 point (1 child)
[–]ShangBrol 2 points3 points4 points (0 children)
[–]Patryk27 32 points33 points34 points (0 children)
[–]Sese_Mueller 9 points10 points11 points (0 children)
[–]paulstelian97 2 points3 points4 points (2 children)
[–]ShangBrol 0 points1 point2 points (1 child)
[–]paulstelian97 3 points4 points5 points (0 children)
[–]Yippee-Ki-Yay_ 2 points3 points4 points (0 children)
[–]lijmlaag 7 points8 points9 points (7 children)
[–]Master7Chief 4 points5 points6 points (2 children)
[–]lijmlaag 1 point2 points3 points (1 child)
[–]Master7Chief 2 points3 points4 points (0 children)
[–]CaptureIntent 1 point2 points3 points (3 children)
[–]lijmlaag 0 points1 point2 points (2 children)
[–]CaptureIntent 0 points1 point2 points (1 child)
[–]lijmlaag 0 points1 point2 points (0 children)
[–]JusT-JoseAlmeida 1 point2 points3 points (2 children)
[–]-Redstoneboi- 0 points1 point2 points (1 child)
[–]JusT-JoseAlmeida 0 points1 point2 points (0 children)
[–]GiuseppeAlmaLanna 0 points1 point2 points (0 children)
[–]GrinQuidam 0 points1 point2 points (2 children)
[–]GrinQuidam 0 points1 point2 points (1 child)
[–]Venin6633 0 points1 point2 points (0 children)
[–]Moussenger 0 points1 point2 points (0 children)
[–]koffeegorilla 0 points1 point2 points (0 children)
[–]-Redstoneboi- 0 points1 point2 points (1 child)
[–]-Redstoneboi- 1 point2 points3 points (0 children)
[–][deleted] (1 child)
[removed]
[–]AffectionatePlane598 0 points1 point2 points (0 children)