Skip to content

Commit 9652c80

Browse files
Talk about recursion as a substitute for looping
This also separates the discussion of looping constructs from that of `const` trait methods and the `?` operator.
1 parent b2fa25c commit 9652c80

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

posts/inside-rust/2019-11-23-const-if-match.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ enabled. However, the other assert macros (e.g., `assert_eq`,
6666
`debug_assert_ne`) remain forbidden, since they need to call `Debug::fmt` on
6767
their arguments.
6868

69-
Also forbidden are looping constructs, `while`, `for`, and `loop`, which will
70-
be [feature-gated separately][52000], and the `?` operator, which calls
71-
`From::from` on the value inside the `Err` variant. The design for
72-
`const` trait methods is still being discussed.
69+
The looping constructs, `while`, `for`, and `loop` are also forbidden and will
70+
be be [feature-gated separately][52000]. As you have see above, loops can be
71+
emulated with recursion as a temporary measure. However, the non-recursive
72+
version will usually be more efficient since rust does not (to my knowledge)
73+
do tail call optimization.
74+
75+
Finally, the `?` operator remains forbidden in a const context, since its
76+
desugaring contains a call to `From::from`. The design for `const` trait
77+
methods is still being discussed, and both `?` and `for`, which desugars to a
78+
call to `IntoIterator::into_iter`, will not be usable until a final decision is
79+
reached.
7380

7481
[52000]: https://github.com/rust-lang/rust/issues/52000
7582

0 commit comments

Comments
 (0)