diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-07-12 22:46:41 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-12 22:46:41 +0200 |
| commit | f169b15e1d8e676ac6a9a7d2b0d12147e13f7ec2 (patch) | |
| tree | 1a1dec2a072b9cee3d618fafb6fa2234a87d7476 /src | |
| parent | 9ffeb26e0b0491fe165911550c63795b76503aa5 (diff) | |
| parent | 9b0623d51f5c9754e63107b50373ff1294c28c61 (diff) | |
| download | rust-f169b15e1d8e676ac6a9a7d2b0d12147e13f7ec2.tar.gz rust-f169b15e1d8e676ac6a9a7d2b0d12147e13f7ec2.zip | |
Rollup merge of #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
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcore/option.rs | 5 | ||||
| -rw-r--r-- | src/libcore/result.rs | 4 |
2 files changed, 5 insertions, 4 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 29169951e46..193cdb15b54 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -178,7 +178,7 @@ impl<T> Option<T> { /// ``` /// /// [`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,8 @@ impl<T> Option<T> { /// ``` /// /// [`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 b64ad149cf4..ba72e1e75f8 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -277,7 +277,7 @@ impl<T, E> Result<T, E> { /// let x: Result<i32, &str> = 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<T, E> Result<T, E> { /// let x: Result<i32, &str> = 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 { |
