Skip to content

Commit f169b15

Browse files
authored
Rollup merge of rust-lang#62431 - czipperz:add-messages-to-must-use-is_-methods, r=scottmcm
Add messages to `Option`'s and `Result`'s `must_use` annotation for `is_*` r? @RalfJung
2 parents 9ffeb26 + 9b0623d commit f169b15

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/libcore/option.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<T> Option<T> {
178178
/// ```
179179
///
180180
/// [`Some`]: #variant.Some
181-
#[must_use]
181+
#[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"]
182182
#[inline]
183183
#[stable(feature = "rust1", since = "1.0.0")]
184184
pub fn is_some(&self) -> bool {
@@ -201,7 +201,8 @@ impl<T> Option<T> {
201201
/// ```
202202
///
203203
/// [`None`]: #variant.None
204-
#[must_use]
204+
#[must_use = "if you intended to assert that this doesn't have a value, consider \
205+
`.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"]
205206
#[inline]
206207
#[stable(feature = "rust1", since = "1.0.0")]
207208
pub fn is_none(&self) -> bool {

src/libcore/result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl<T, E> Result<T, E> {
277277
/// let x: Result<i32, &str> = Err("Some error message");
278278
/// assert_eq!(x.is_ok(), false);
279279
/// ```
280-
#[must_use]
280+
#[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"]
281281
#[inline]
282282
#[stable(feature = "rust1", since = "1.0.0")]
283283
pub fn is_ok(&self) -> bool {
@@ -302,7 +302,7 @@ impl<T, E> Result<T, E> {
302302
/// let x: Result<i32, &str> = Err("Some error message");
303303
/// assert_eq!(x.is_err(), true);
304304
/// ```
305-
#[must_use]
305+
#[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"]
306306
#[inline]
307307
#[stable(feature = "rust1", since = "1.0.0")]
308308
pub fn is_err(&self) -> bool {

0 commit comments

Comments
 (0)