Add must_use annotations to Result::is_ok and is_err

This commit is contained in:
Alex Gaynor 2019-04-02 22:09:56 +00:00 committed by Alex Gaynor
parent 3750348daf
commit ce5d69480a
5 changed files with 12 additions and 8 deletions

View File

@ -178,6 +178,7 @@ impl<T> Option<T> {
/// ``` /// ```
/// ///
/// [`Some`]: #variant.Some /// [`Some`]: #variant.Some
#[must_use]
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn is_some(&self) -> bool { pub fn is_some(&self) -> bool {
@ -200,6 +201,7 @@ impl<T> Option<T> {
/// ``` /// ```
/// ///
/// [`None`]: #variant.None /// [`None`]: #variant.None
#[must_use]
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn is_none(&self) -> bool { pub fn is_none(&self) -> bool {

View File

@ -277,6 +277,7 @@ impl<T, E> Result<T, E> {
/// let x: Result<i32, &str> = Err("Some error message"); /// let x: Result<i32, &str> = Err("Some error message");
/// assert_eq!(x.is_ok(), false); /// assert_eq!(x.is_ok(), false);
/// ``` /// ```
#[must_use]
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn is_ok(&self) -> bool { pub fn is_ok(&self) -> bool {
@ -301,6 +302,7 @@ impl<T, E> Result<T, E> {
/// let x: Result<i32, &str> = Err("Some error message"); /// let x: Result<i32, &str> = Err("Some error message");
/// assert_eq!(x.is_err(), true); /// assert_eq!(x.is_err(), true);
/// ``` /// ```
#[must_use]
#[inline] #[inline]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
pub fn is_err(&self) -> bool { pub fn is_err(&self) -> bool {

View File

@ -1471,7 +1471,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok(); assert!(OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok());
} }
#[test] #[test]
@ -1481,7 +1481,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err(); assert!(!OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err());
} }
} }
@ -1868,7 +1868,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_ok(); assert!(OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_ok());
} }
#[test] #[test]
@ -1878,7 +1878,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_err(); assert!(!OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_err());
} }
#[test] #[test]
@ -1888,7 +1888,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok(); assert!(OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok());
} }
#[test] #[test]
@ -1898,7 +1898,7 @@ mod tests {
let x = Box::new(123_i32); let x = Box::new(123_i32);
let y: Box<dyn Any> = x; let y: Box<dyn Any> = x;
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err(); assert!(!OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err());
} }
#[test] #[test]

View File

@ -1005,7 +1005,7 @@ impl<T> SyncSender<T> {
/// thread::spawn(move || { /// thread::spawn(move || {
/// // This will return an error and send /// // This will return an error and send
/// // no message if the buffer is full /// // no message if the buffer is full
/// sync_sender2.try_send(3).is_err(); /// let _ = sync_sender2.try_send(3);
/// }); /// });
/// ///
/// let mut msg; /// let mut msg;

View File

@ -11,5 +11,5 @@ struct Str {
fn main() { fn main() {
let str: Option<&Str> = None; let str: Option<&Str> = None;
str.is_some(); let _ = str.is_some();
} }