Skip to content

Update bool and ! docs #80590

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

Merged
merged 2 commits into from
Jan 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions library/std/src/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc.,
/// which allow us to perform boolean operations using `&`, `|` and `!`.
///
/// `if` always demands a `bool` value. [`assert!`], which is an important macro in testing,
/// checks whether an expression returns `true` and panics if it isn't.
/// `if` requires a `bool` value as its conditional. [`assert!`], which is an
/// important macro in testing, checks whether an expression is `true` and panics
/// if it isn't.
Comment on lines +15 to +16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could reword

checks whether an expression is true and panics if it isn't.

as

panics if the expression is false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting

checks whether an expression is true and panics if it's false

or something else? I feel like maybe it's good enough as it is now, but open to changing it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thankfully Rust isn’t Haskell and doesn’t have to worry about pervasive bottoms in data, so it really is the case for us that “isn’t true” necessarily implies “is false”. 😄

///
/// ```
/// let bool_val = true & false | false;
Expand All @@ -25,7 +26,7 @@
///
/// # Examples
///
/// A trivial example of the usage of `bool`,
/// A trivial example of the usage of `bool`:
///
/// ```
/// let praise_the_borrow_checker = true;
Expand Down Expand Up @@ -122,9 +123,9 @@ mod prim_bool {}
/// `!`, if we have to call [`String::from_str`] for some reason the result will be a
/// [`Result<String, !>`] which we can unpack like this:
///
/// ```ignore (string-from-str-error-type-is-not-never-yet)
/// #[feature(exhaustive_patterns)]
/// // NOTE: this does not work today!
/// ```
/// #![feature(exhaustive_patterns)]
/// use std::str::FromStr;
/// let Ok(s) = String::from_str("hello");
/// ```
///
Expand Down