Rollup of 11 pull requests by Centril · Pull Request #59293 · rust-lang/rust (original) (raw)
Add todo!() macro
The primary use-case of todo!()
macro is to be a much easier to type
alternative to unimplemented!()
macro.
EDIT: hide unpopular proposal about re-purposing unimplemented
With the addition of TODO, you have three nuanced choices for a
!
-returning macro (in addition to a good-old panic we all love):
- todo!()
- unreachable!()
- unimplemented!()
Here's a rough guideline what each one means:
todo
: use it during development, as a "hole" or placeholder. It might be a good idea to add a pre-commit hook which checks thattodo
is not accidentally committed.unreachable!()
: use it when your code can statically guarantee that some situation can not happen. If you use a library and hitunreachable!()
in the library's code, it's definitely a bug in the library. It's OK to haveunreachable!()
in the code base, although, if possible, it's better to replace it with compiler-verified exhaustive checks.unimplemented!()
: use it when the type checker forces you to handle some situation, but there's a contract that a callee must not actually call the code. If you use a library and hitunimplemented!()
, it's probably a bug in your code, though it could be a bug in the library (or library docs) as well. It is ok-ish to see anunimplemented!()
in real code, but it usually signifies a clunky, eyebrow-rising API.