From ce5d69480a644011acedd3072eaef61cd72e5850 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 2 Apr 2019 22:09:56 +0000 Subject: [PATCH] Add must_use annotations to Result::is_ok and is_err --- src/libcore/option.rs | 2 ++ src/libcore/result.rs | 2 ++ src/librustc_data_structures/owning_ref/mod.rs | 12 ++++++------ src/libstd/sync/mpsc/mod.rs | 2 +- src/test/run-pass/issues/issue-18353.rs | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 3da92c0a05a..68ef087d84b 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -178,6 +178,7 @@ impl Option { /// ``` /// /// [`Some`]: #variant.Some + #[must_use] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_some(&self) -> bool { @@ -200,6 +201,7 @@ impl Option { /// ``` /// /// [`None`]: #variant.None + #[must_use] #[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 9b7b8368986..e22a9ebbca4 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -277,6 +277,7 @@ impl Result { /// let x: Result = Err("Some error message"); /// assert_eq!(x.is_ok(), false); /// ``` + #[must_use] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_ok(&self) -> bool { @@ -301,6 +302,7 @@ impl Result { /// let x: Result = Err("Some error message"); /// assert_eq!(x.is_err(), true); /// ``` + #[must_use] #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn is_err(&self) -> bool { diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index 236559dcd7c..0301891c9b2 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -1471,7 +1471,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); + assert!(OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok()); } #[test] @@ -1481,7 +1481,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); + assert!(!OwningRef::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err()); } } @@ -1868,7 +1868,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_ok(); + assert!(OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_ok()); } #[test] @@ -1878,7 +1878,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_err(); + assert!(!OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::().ok_or(())).is_err()); } #[test] @@ -1888,7 +1888,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok(); + assert!(OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_ok()); } #[test] @@ -1898,7 +1898,7 @@ mod tests { let x = Box::new(123_i32); let y: Box = x; - OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err(); + assert!(!OwningRefMut::new(y).try_map(|x| x.downcast_ref::().ok_or(())).is_err()); } #[test] diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index bc32b8e47b3..685c7909ff2 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1005,7 +1005,7 @@ impl SyncSender { /// thread::spawn(move || { /// // This will return an error and send /// // no message if the buffer is full - /// sync_sender2.try_send(3).is_err(); + /// let _ = sync_sender2.try_send(3); /// }); /// /// let mut msg; diff --git a/src/test/run-pass/issues/issue-18353.rs b/src/test/run-pass/issues/issue-18353.rs index aaa896b66c5..3d15c9980c3 100644 --- a/src/test/run-pass/issues/issue-18353.rs +++ b/src/test/run-pass/issues/issue-18353.rs @@ -11,5 +11,5 @@ struct Str { fn main() { let str: Option<&Str> = None; - str.is_some(); + let _ = str.is_some(); }