Skip to content

Commit ff5ba73

Browse files
Document the optional extra arguments to assert_eq!() / assert_ne!()
And clarify that those arguments in assert!() are in fact formattable.
1 parent b27c709 commit ff5ba73

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libcore/macros.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ macro_rules! panic {
4545
/// Other use-cases of `assert!` include [testing] and enforcing run-time
4646
/// invariants in safe code (whose violation cannot result in unsafety).
4747
///
48-
/// This macro has a second version, where a custom panic message can be provided.
48+
/// This macro has a second version, where a custom panic message can
49+
/// be provided with or without arguments for formatting.
4950
///
5051
/// [testing]: ../book/testing.html
5152
///
@@ -87,12 +88,17 @@ macro_rules! assert {
8788
/// On panic, this macro will print the values of the expressions with their
8889
/// debug representations.
8990
///
91+
/// Like `assert!()`, this macro has a second version, where a custom
92+
/// panic message can be provided.
93+
///
9094
/// # Examples
9195
///
9296
/// ```
9397
/// let a = 3;
9498
/// let b = 1 + 2;
9599
/// assert_eq!(a, b);
100+
///
101+
/// assert_eq!(a, b, "we are testing addition with {} and {}", a, b);
96102
/// ```
97103
#[macro_export]
98104
#[stable(feature = "rust1", since = "1.0.0")]
@@ -125,12 +131,17 @@ macro_rules! assert_eq {
125131
/// On panic, this macro will print the values of the expressions with their
126132
/// debug representations.
127133
///
134+
/// Like `assert!()`, this macro has a second version, where a custom
135+
/// panic message can be provided.
136+
///
128137
/// # Examples
129138
///
130139
/// ```
131140
/// let a = 3;
132141
/// let b = 2;
133142
/// assert_ne!(a, b);
143+
///
144+
/// assert_ne!(a, b, "we are testing that the values are not equal");
134145
/// ```
135146
#[macro_export]
136147
#[stable(feature = "assert_ne", since = "1.12.0")]

0 commit comments

Comments
 (0)