-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Update docs for assert! and debug_assert! #35072
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -32,8 +32,19 @@ macro_rules! panic { | |
|
||
/// Ensure that a boolean expression is `true` at runtime. | ||
/// | ||
/// This will invoke the `panic!` macro if the provided expression cannot be | ||
/// evaluated to `true` at runtime. | ||
/// This will ensure the termination of the program if the provided expression | ||
/// cannot be evaluated to `true` at runtime by means of an unrecoverable error | ||
/// (not necessarily a `panic!`, can also be an `abort`). | ||
/// | ||
/// Assertions are always checked in both debug and release builds, and cannot | ||
/// be disabled. | ||
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. It would be nice to point to |
||
/// | ||
/// Unsafe code relies on `assert!` to enforce run-time invariants that, if | ||
/// violated could lead to unsafety. | ||
/// | ||
/// Other use-cases of `assert!` include | ||
/// [testing](https://doc.rust-lang.org/book/testing.html) and enforcing | ||
/// run-time invariants in safe code (whose violation cannot result in unsafety). | ||
/// | ||
/// This macro has a second version, where a custom panic message can be provided. | ||
/// | ||
|
@@ -123,6 +134,13 @@ macro_rules! assert_eq { | |
/// expensive to be present in a release build but may be helpful during | ||
/// development. | ||
/// | ||
/// An unchecked assertion allows a program in an inconsistent state to keep | ||
/// running, which might have unexpected consequences but does not introduce | ||
/// unsafety as long as this only happens in safe code. The performance cost | ||
/// of assertions, is however, not measurable in general. Replacing `assert!` | ||
/// with `debug_assert!` is thus only encourage after thorough profiling, and | ||
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. "encouraged" |
||
/// more importantly, only in safe code! | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
|
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.
So, here's my one concern with this wording: it will always panic, the key is that panic can be either unwinding or abort. I would just stick to saying that this panics.