Skip to content

Commit f5d1128

Browse files
committed
Auto merge of #39210 - GuillaumeGomez:GuillaumeGomez-patch-1, r=frewsxcv
Specify the result of integer cast on boolean Fixes #39190. r? @frewsxcv
2 parents 8ba01a1 + b09305e commit f5d1128

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/libstd/primitive_docs.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
//
1313
/// The boolean type.
1414
///
15-
/// The `bool` represents a value, which could only be either `true` or `false`.
15+
/// The `bool` represents a value, which could only be either `true` or `false`. If you cast
16+
/// a `bool` into an integer, `true` will be 1 and `false` will be 0.
1617
///
1718
/// # Basic usage
1819
///
@@ -56,6 +57,13 @@
5657
///
5758
/// Also, since `bool` implements the [`Copy`](marker/trait.Copy.html) trait, we don't
5859
/// have to worry about the move semantics (just like the integer and float primitives).
60+
///
61+
/// Now an example of `bool` cast to integer type:
62+
///
63+
/// ```
64+
/// assert_eq!(true as i32, 1);
65+
/// assert_eq!(false as i32, 0);
66+
/// ```
5967
#[stable(feature = "rust1", since = "1.0.0")]
6068
mod prim_bool { }
6169

0 commit comments

Comments
 (0)