Skip to content

Commit a5bc786

Browse files
committed
Auto merge of #67445 - llogiq:todo, r=dtolnay
Differentiate todo! and unimplemented! This updates the panic message and docs to make it clear that `todo!` is for unfinished code and `unimplemented!` is for partial trait or enum impls. r? @Centril
2 parents a9c1c04 + f4d0a04 commit a5bc786

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

src/libcore/macros/mod.rs

+25-20
Original file line numberDiff line numberDiff line change
@@ -557,13 +557,15 @@ macro_rules! unreachable {
557557
});
558558
}
559559

560-
/// Indicates unfinished code by panicking with a message of "not yet implemented".
560+
/// Indicates unimplemented code by panicking with a message of "not implemented".
561561
///
562562
/// This allows the your code to type-check, which is useful if you are prototyping or
563563
/// implementing a trait that requires multiple methods which you don't plan of using all of.
564564
///
565-
/// There is no difference between `unimplemented!` and `todo!` apart from the
566-
/// name.
565+
/// The difference between `unimplemented!` and [`todo!`](macro.todo.html) is that while `todo!`
566+
/// conveys an intent of implementing the functionality later and the message is "not yet
567+
/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
568+
/// Also some IDEs will mark `todo!`s.
567569
///
568570
/// # Panics
569571
///
@@ -574,7 +576,7 @@ macro_rules! unreachable {
574576
///
575577
/// # Examples
576578
///
577-
/// Here's an example of some in-progress code. We have a trait `Foo`:
579+
/// Say we have a trait `Foo`:
578580
///
579581
/// ```
580582
/// trait Foo {
@@ -584,13 +586,13 @@ macro_rules! unreachable {
584586
/// }
585587
/// ```
586588
///
587-
/// We want to implement `Foo` for 'MyStruct', but so far we only know how to
588-
/// implement the `bar()` function. `baz()` and `qux()` will still need to be defined
589+
/// We want to implement `Foo` for 'MyStruct', but for some reason it only makes sense
590+
/// to implement the `bar()` function. `baz()` and `qux()` will still need to be defined
589591
/// in our implementation of `Foo`, but we can use `unimplemented!` in their definitions
590592
/// to allow our code to compile.
591593
///
592-
/// In the meantime, we want to have our program stop running once these
593-
/// unimplemented functions are reached.
594+
/// We still want to have our program stop running if the unimplemented methods are
595+
/// reached.
594596
///
595597
/// ```
596598
/// # trait Foo {
@@ -606,19 +608,18 @@ macro_rules! unreachable {
606608
/// }
607609
///
608610
/// fn baz(&self) {
609-
/// // We aren't sure how to even start writing baz yet,
610-
/// // so we have no logic here at all.
611-
/// // This will display "thread 'main' panicked at 'not yet implemented'".
611+
/// // It makes no sense to `baz` a `MyStruct`, so we have no logic here
612+
/// // at all.
613+
/// // This will display "thread 'main' panicked at 'not implemented'".
612614
/// unimplemented!();
613615
/// }
614616
///
615617
/// fn qux(&self) -> Result<u64, ()> {
616-
/// let n = self.bar();
617618
/// // We have some logic here,
618-
/// // so we can use unimplemented! to display what we have so far.
619+
/// // We can add a message to unimplemented! to display our omission.
619620
/// // This will display:
620-
/// // "thread 'main' panicked at 'not yet implemented: we need to divide by 2'".
621-
/// unimplemented!("we need to divide by {}", n);
621+
/// // "thread 'main' panicked at 'not implemented: MyStruct isn't quxable'".
622+
/// unimplemented!("MyStruct isn't quxable");
622623
/// }
623624
/// }
624625
///
@@ -630,17 +631,21 @@ macro_rules! unreachable {
630631
#[macro_export]
631632
#[stable(feature = "rust1", since = "1.0.0")]
632633
macro_rules! unimplemented {
633-
() => (panic!("not yet implemented"));
634-
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));
634+
() => (panic!("not implemented"));
635+
($($arg:tt)+) => (panic!("not implemented: {}", $crate::format_args!($($arg)+)));
635636
}
636637

637638
/// Indicates unfinished code.
638639
///
639640
/// This can be useful if you are prototyping and are just looking to have your
640641
/// code typecheck.
641642
///
642-
/// There is no difference between `unimplemented!` and `todo!` apart from the
643-
/// name.
643+
/// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
644+
/// an intent of implementing the functionality later and the message is "not yet
645+
/// implemented", `unimplemented!` makes no such claims. Its message is "not implemented".
646+
/// Also some IDEs will mark `todo!`s.
647+
///
648+
/// [`unimplemented!`]: macro.unimplemented.html
644649
///
645650
/// # Panics
646651
///
@@ -683,7 +688,7 @@ macro_rules! unimplemented {
683688
/// let s = MyStruct;
684689
/// s.bar();
685690
///
686-
/// // we aren't even using baz() yet, so this is fine.
691+
/// // we aren't even using baz(), so this is fine.
687692
/// }
688693
/// ```
689694
#[macro_export]
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern:not yet implemented
1+
// error-pattern:not implemented
22
fn main() {
33
unimplemented!()
44
}

src/test/ui/consts/const-eval/const_panic.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error: any use of this value will cause an error
2525
LL | pub const X: () = unimplemented!();
2626
| ------------------^^^^^^^^^^^^^^^^-
2727
| |
28-
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic.rs:10:19
28+
| the evaluated program panicked at 'not implemented', $DIR/const_panic.rs:10:19
2929
|
3030
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3131

src/test/ui/consts/const-eval/const_panic_libcore.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error: any use of this value will cause an error
2525
LL | const X: () = unimplemented!();
2626
| --------------^^^^^^^^^^^^^^^^-
2727
| |
28-
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore.rs:11:15
28+
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore.rs:11:15
2929
|
3030
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3131

src/test/ui/consts/const-eval/const_panic_libcore_main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error: any use of this value will cause an error
2525
LL | const X: () = unimplemented!();
2626
| --------------^^^^^^^^^^^^^^^^-
2727
| |
28-
| the evaluated program panicked at 'not yet implemented', $DIR/const_panic_libcore_main.rs:15:15
28+
| the evaluated program panicked at 'not implemented', $DIR/const_panic_libcore_main.rs:15:15
2929
|
3030
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3131

0 commit comments

Comments
 (0)