Does todo! panic?

Reading the docs over at todo in std - Rust which states:
"This will always panic!."

However, I ran the example code, and the code does not panic.

Should this read "This will never panic!."?

How does one raise markup required edits in the docs?

// we aren't even using baz(), so this is fine

Panics if you use baz. Playground

1 Like

The todo!() in the example is never executed.

Adding an example where the macro is executed and thus panics seems reasonable.

When the docs say that a macro or function will "do something," you can infer that they mean that they will do it when execution reaches that expression[1]. It's so inherent in the execution model Rust uses that it's rarely spelled out explicitly on a case-by-case basis, though in principle it could be, since it's true of every function's documented behaviour.

The example code never calls baz(), so execution never reaches the todo!(…) in baz's body, so it never panics due to that call. If you add something to call baz(), execution then enters baz and reaches the todo!(…) macro, which promptly causes a panic.


[1]: That is, after execution enters the expression, and before it leaves it, at least as far as the semantics of the Rust programming language are concerned.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.