about summary refs log tree commit diff
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2018-03-30 23:06:05 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2018-03-30 23:06:05 -0700
commitfb7deda27419eae61da3cbf5a5b1b4f51ae16d04 (patch)
tree9dc51de2af727ff8741edb1c3f2b1665374da21d
parent80785a547d29519dbdb5781437ec318fb210b980 (diff)
downloadrust-fb7deda27419eae61da3cbf5a5b1b4f51ae16d04.tar.gz
rust-fb7deda27419eae61da3cbf5a5b1b4f51ae16d04.zip
Add #[must_use] to a few standard library methods
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 :)
-rw-r--r--src/liballoc/borrow.rs1
-rw-r--r--src/libcore/clone.rs1
-rw-r--r--src/libcore/iter/iterator.rs1
-rw-r--r--src/librustc_mir/build/mod.rs2
4 files changed, 4 insertions, 1 deletions
diff --git a/src/liballoc/borrow.rs b/src/liballoc/borrow.rs
index acae0daa86b..c6741ddb822 100644
--- a/src/liballoc/borrow.rs
+++ b/src/liballoc/borrow.rs
@@ -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.
diff --git a/src/libcore/clone.rs b/src/libcore/clone.rs
index d25f498b99e..c175ae15d28 100644
--- a/src/libcore/clone.rs
+++ b/src/libcore/clone.rs
@@ -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`.
diff --git a/src/libcore/iter/iterator.rs b/src/libcore/iter/iterator.rs
index 31f77f92435..42fd9051292 100644
--- a/src/libcore/iter/iterator.rs
+++ b/src/libcore/iter/iterator.rs
@@ -1368,6 +1368,7 @@ pub trait Iterator {
     /// [`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)
     }
diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs
index 8494c043f90..6f5fcc9e421 100644
--- a/src/librustc_mir/build/mod.rs
+++ b/src/librustc_mir/build/mod.rs
@@ -317,7 +317,7 @@ newtype_index!(ScopeId);
 /// 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 {