]> git.lizzy.rs Git - rust.git/commitdiff
Add #[must_use] to a few standard library methods
authorScott McMurray <scottmcm@users.noreply.github.com>
Sat, 31 Mar 2018 06:06:05 +0000 (23:06 -0700)
committerScott McMurray <scottmcm@users.noreply.github.com>
Sat, 31 Mar 2018 06:06:05 +0000 (23:06 -0700)
Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged.

Discuss :)

src/liballoc/borrow.rs
src/libcore/clone.rs
src/libcore/iter/iterator.rs
src/librustc_mir/build/mod.rs

index acae0daa86b6bd30e30f12ce7f531594c3b7c233..c6741ddb822d5bb9114889bc71fdd2203f72e559 100644 (file)
@@ -59,6 +59,7 @@ pub trait ToOwned {
     /// let vv: Vec<i32> = v.to_owned();
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[must_use = "cloning is often expensive and is not expected to have side effects"]
     fn to_owned(&self) -> Self::Owned;
 
     /// Uses borrowed data to replace owned data, usually by cloning.
index d25f498b99efea68c8eb8462028f8cdda6ecd0e1..c175ae15d28fe03636778725b23dbd370c24b684 100644 (file)
@@ -105,6 +105,7 @@ pub trait Clone : Sized {
     /// assert_eq!("Hello", hello.clone());
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[must_use = "cloning is often expensive and is not expected to have side effects"]
     fn clone(&self) -> Self;
 
     /// Performs copy-assignment from `source`.
index 31f77f92435d83ff72a9f04582bb6717f1c1bedd..42fd90512923bc4fc1f977fb3a9347931a009694 100644 (file)
@@ -1368,6 +1368,7 @@ fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
     /// [`Result`]: ../../std/result/enum.Result.html
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
+    #[must_use = "if you really need to exhaust the iterator, consider `.for_each(drop)` instead"]
     fn collect<B: FromIterator<Self::Item>>(self) -> B where Self: Sized {
         FromIterator::from_iter(self)
     }
index 8494c043f90fcd28ef2e6ea3b3b20a0d0a1dceca..6f5fcc9e421cc115d780356092c1563455c30201 100644 (file)
@@ -317,7 +317,7 @@ struct CFG<'tcx> {
 /// macro (and methods below) makes working with `BlockAnd` much more
 /// convenient.
 
-#[must_use] // if you don't use one of these results, you're leaving a dangling edge
+#[must_use = "if you don't use one of these results, you're leaving a dangling edge"]
 struct BlockAnd<T>(BasicBlock, T);
 
 trait BlockAndExtension {