-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add todo!() macro #56348
Merged
Merged
Add todo!() macro #56348
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -559,6 +559,65 @@ macro_rules! unimplemented { | |
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*))); | ||
} | ||
|
||
/// A standardized placeholder for marking unfinished code. | ||
/// | ||
/// This can be useful if you are prototyping and are just looking to have your | ||
/// code typecheck. `todo!` works exactly like `unimplemented!`, there only | ||
/// difference between the two macros is the name. | ||
/// | ||
/// # Panics | ||
/// | ||
/// This will always [panic!](macro.panic.html) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this say "panics"? |
||
/// | ||
/// # Examples | ||
/// | ||
/// Here's an example of some in-progress code. We have a trait `Foo`: | ||
/// | ||
/// ``` | ||
/// trait Foo { | ||
/// fn bar(&self); | ||
/// fn baz(&self); | ||
/// } | ||
/// ``` | ||
/// | ||
/// We want to implement `Foo` on one of our types, but we also want to work on | ||
/// just `bar()` first. In order for our code to compile, we need to implement | ||
/// `baz()`, so we can use `todo!`: | ||
/// | ||
/// ``` | ||
/// #![feature(todo_macro)] | ||
/// | ||
/// # trait Foo { | ||
/// # fn bar(&self); | ||
/// # fn baz(&self); | ||
/// # } | ||
/// struct MyStruct; | ||
/// | ||
/// impl Foo for MyStruct { | ||
/// fn bar(&self) { | ||
/// // implementation goes here | ||
/// } | ||
/// | ||
/// fn baz(&self) { | ||
/// // let's not worry about implementing baz() for now | ||
/// todo!(); | ||
/// } | ||
/// } | ||
/// | ||
/// fn main() { | ||
/// let s = MyStruct; | ||
/// s.bar(); | ||
/// | ||
/// // we aren't even using baz() yet, so this is fine. | ||
/// } | ||
/// ``` | ||
#[macro_export] | ||
#[unstable(feature = "todo_macro", issue = "59277")] | ||
macro_rules! todo { | ||
() => (panic!("not yet implemented")); | ||
($($arg:tt)+) => (panic!("not yet implemented: {}", format_args!($($arg)*))); | ||
} | ||
|
||
/// A macro to create an array of [`MaybeUninit`] | ||
/// | ||
/// This macro constructs an uninitialized array of the type `[MaybeUninit<K>; N]`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unimplemented macro also has this sentence in the docs so you probably want to re-frame that documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that only when we stabilize
todo
: #56348 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't macros insta-stable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are other unstable macros already, like
concat_idents!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steveklabnik I believe not necessarily. The
dbg!()
macro went through nightly first, and is only now landing on stable.