Hacker News new | ask | show | jobs
by phire 2123 days ago
Short circuiting introduces conditional branching. If you call a function on the right hand side of a || or && it might or might not be executed depending on the value of the left hand side.

Until this version of rust, all conditional branches were banned from const functions.

I guess to keep things simple they just banned any feature that might cause branching.

2 comments

Why is branching a problem? Since `if` is now enabled in a const fn, it's trivial to rewrite && with & and if.
`if` wasn't enabled before, so `&&` wasn't enabled. Now that `if` is enabled, `&&` now works too.
Ahh that makes a lot of sense, if you're going to have a compiler insert the result of a function having conditional branching seems a bit gnarly I guess?
For the history of this feature request, see https://github.com/rust-lang/rust/issues/29608 as a starting point.
It's conditional based on what's ultimately constant data, so you end up with predictable output regardless.