Skip to content

Commit 92702c1

Browse files
authored
Rollup merge of rust-lang#59648 - alex:must-use-result, r=alexcrichton
Add must_use annotations to Result::is_ok and is_err Discussed in rust-lang#59610
2 parents 9217fe0 + ce5d694 commit 92702c1

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

src/libcore/option.rs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl<T> Option<T> {
178178
/// ```
179179
///
180180
/// [`Some`]: #variant.Some
181+
#[must_use]
181182
#[inline]
182183
#[stable(feature = "rust1", since = "1.0.0")]
183184
pub fn is_some(&self) -> bool {
@@ -200,6 +201,7 @@ impl<T> Option<T> {
200201
/// ```
201202
///
202203
/// [`None`]: #variant.None
204+
#[must_use]
203205
#[inline]
204206
#[stable(feature = "rust1", since = "1.0.0")]
205207
pub fn is_none(&self) -> bool {

src/libcore/result.rs

+2
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ impl<T, E> Result<T, E> {
277277
/// let x: Result<i32, &str> = Err("Some error message");
278278
/// assert_eq!(x.is_ok(), false);
279279
/// ```
280+
#[must_use]
280281
#[inline]
281282
#[stable(feature = "rust1", since = "1.0.0")]
282283
pub fn is_ok(&self) -> bool {
@@ -301,6 +302,7 @@ impl<T, E> Result<T, E> {
301302
/// let x: Result<i32, &str> = Err("Some error message");
302303
/// assert_eq!(x.is_err(), true);
303304
/// ```
305+
#[must_use]
304306
#[inline]
305307
#[stable(feature = "rust1", since = "1.0.0")]
306308
pub fn is_err(&self) -> bool {

src/librustc_data_structures/owning_ref/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ mod tests {
14711471
let x = Box::new(123_i32);
14721472
let y: Box<dyn Any> = x;
14731473

1474-
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok();
1474+
assert!(OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok());
14751475
}
14761476

14771477
#[test]
@@ -1481,7 +1481,7 @@ mod tests {
14811481
let x = Box::new(123_i32);
14821482
let y: Box<dyn Any> = x;
14831483

1484-
OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err();
1484+
assert!(!OwningRef::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err());
14851485
}
14861486
}
14871487

@@ -1868,7 +1868,7 @@ mod tests {
18681868
let x = Box::new(123_i32);
18691869
let y: Box<dyn Any> = x;
18701870

1871-
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_ok();
1871+
assert!(OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_ok());
18721872
}
18731873

18741874
#[test]
@@ -1878,7 +1878,7 @@ mod tests {
18781878
let x = Box::new(123_i32);
18791879
let y: Box<dyn Any> = x;
18801880

1881-
OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_err();
1881+
assert!(!OwningRefMut::new(y).try_map_mut(|x| x.downcast_mut::<i32>().ok_or(())).is_err());
18821882
}
18831883

18841884
#[test]
@@ -1888,7 +1888,7 @@ mod tests {
18881888
let x = Box::new(123_i32);
18891889
let y: Box<dyn Any> = x;
18901890

1891-
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok();
1891+
assert!(OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_ok());
18921892
}
18931893

18941894
#[test]
@@ -1898,7 +1898,7 @@ mod tests {
18981898
let x = Box::new(123_i32);
18991899
let y: Box<dyn Any> = x;
19001900

1901-
OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err();
1901+
assert!(!OwningRefMut::new(y).try_map(|x| x.downcast_ref::<i32>().ok_or(())).is_err());
19021902
}
19031903

19041904
#[test]

src/libstd/sync/mpsc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ impl<T> SyncSender<T> {
10051005
/// thread::spawn(move || {
10061006
/// // This will return an error and send
10071007
/// // no message if the buffer is full
1008-
/// sync_sender2.try_send(3).is_err();
1008+
/// let _ = sync_sender2.try_send(3);
10091009
/// });
10101010
///
10111011
/// let mut msg;

src/test/run-pass/issues/issue-18353.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ struct Str {
1111

1212
fn main() {
1313
let str: Option<&Str> = None;
14-
str.is_some();
14+
let _ = str.is_some();
1515
}

0 commit comments

Comments
 (0)