Skip to content

Commit

Permalink
Add must_use annotations to Result::is_ok and is_err
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored and Alex Gaynor committed Apr 8, 2019
1 parent 3750348 commit ce5d694
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_data_structures/owning_ref/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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());
}
}

Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issues/issue-18353.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ struct Str {

fn main() {
let str: Option<&Str> = None;
str.is_some();
let _ = str.is_some();
}

0 comments on commit ce5d694

Please sign in to comment.