Add must_use annotations to Result::is_ok and is_err
This commit is contained in:
parent
3750348daf
commit
ce5d69480a
@ -178,6 +178,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
///
|
||||
/// [`Some`]: #variant.Some
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn is_some(&self) -> bool {
|
||||
@ -200,6 +201,7 @@ impl<T> Option<T> {
|
||||
/// ```
|
||||
///
|
||||
/// [`None`]: #variant.None
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn is_none(&self) -> bool {
|
||||
|
@ -277,6 +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]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
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");
|
||||
/// assert_eq!(x.is_err(), true);
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[inline]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub fn is_err(&self) -> bool {
|
||||
|
@ -1471,7 +1471,7 @@ mod tests {
|
||||
let x = Box::new(123_i32);
|
||||
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]
|
||||
@ -1481,7 +1481,7 @@ mod tests {
|
||||
let x = Box::new(123_i32);
|
||||
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 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]
|
||||
@ -1878,7 +1878,7 @@ mod tests {
|
||||
let x = Box::new(123_i32);
|
||||
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]
|
||||
@ -1888,7 +1888,7 @@ mod tests {
|
||||
let x = Box::new(123_i32);
|
||||
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]
|
||||
@ -1898,7 +1898,7 @@ mod tests {
|
||||
let x = Box::new(123_i32);
|
||||
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]
|
||||
|
@ -1005,7 +1005,7 @@ impl<T> SyncSender<T> {
|
||||
/// 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;
|
||||
|
@ -11,5 +11,5 @@ struct Str {
|
||||
|
||||
fn main() {
|
||||
let str: Option<&Str> = None;
|
||||
str.is_some();
|
||||
let _ = str.is_some();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user