From 145385e7c3fbb242e3024ad0368f2cfd95f5666e Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Fri, 5 Jul 2019 20:57:25 -0700 Subject: [PATCH 1/2] Add messages to Option and Result must_use for is_* --- src/libcore/option.rs | 4 ++-- src/libcore/result.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b27fd4098e167..9174ebae171da 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -178,7 +178,7 @@ impl Option { /// ``` /// /// [`Some`]: #variant.Some - #[must_use] + #[must_use = "if you intended to assert that this has a value, consider `.unwrap()` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_some(&self) -> bool { @@ -201,7 +201,7 @@ impl Option { /// ``` /// /// [`None`]: #variant.None - #[must_use] + #[must_use = "if you intended to assert that this doesn't have a value, consider `.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_none(&self) -> bool { diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 8a09877ce1f4b..a31ac212dea24 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -277,7 +277,7 @@ impl Result { /// let x: Result = Err("Some error message"); /// assert_eq!(x.is_ok(), false); /// ``` - #[must_use] + #[must_use = "if you intended to assert that this is ok, consider `.unwrap()` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_ok(&self) -> bool { @@ -302,7 +302,7 @@ impl Result { /// let x: Result = Err("Some error message"); /// assert_eq!(x.is_err(), true); /// ``` - #[must_use] + #[must_use = "if you intended to assert that this is err, consider `.unwrap_err()` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_err(&self) -> bool { From 9b0623d51f5c9754e63107b50373ff1294c28c61 Mon Sep 17 00:00:00 2001 From: Chris Gregory Date: Fri, 5 Jul 2019 21:38:35 -0700 Subject: [PATCH 2/2] Wrap line --- src/libcore/option.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 9174ebae171da..2c148ec485767 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -201,7 +201,8 @@ impl Option { /// ``` /// /// [`None`]: #variant.None - #[must_use = "if you intended to assert that this doesn't have a value, consider `.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"] + #[must_use = "if you intended to assert that this doesn't have a value, consider \ + `.and_then(|| panic!(\"`Option` had a value when expected `None`\"))` instead"] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_none(&self) -> bool {