about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-04-17 11:36:56 -0700
committerJosh Stone <jistone@redhat.com>2020-04-17 11:36:56 -0700
commit7c4ca59f4b10d20f0f3e902f847641311abb093c (patch)
tree3046706957c513a61423ce7b6720611a87dbcbb9
parent8d67f576b56e8fc98a31123e5963f8d00e40611c (diff)
downloadrust-7c4ca59f4b10d20f0f3e902f847641311abb093c.tar.gz
rust-7c4ca59f4b10d20f0f3e902f847641311abb093c.zip
Lint must_use on mem::replace
This adds a hint on `mem::replace`, "if you don't need the old value,
you can just assign the new value directly". This is in similar spirit
to the `must_use` on `ManuallyDrop::take`.
-rw-r--r--src/libcore/mem/mod.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/libcore/mem/mod.rs b/src/libcore/mem/mod.rs
index 07f7d28bb75..3fa2b7a2d04 100644
--- a/src/libcore/mem/mod.rs
+++ b/src/libcore/mem/mod.rs
@@ -808,6 +808,7 @@ pub fn take<T: Default>(dest: &mut T) -> T {
 /// [`Clone`]: ../../std/clone/trait.Clone.html
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
+#[must_use = "if you don't need the old value, you can just assign the new value directly"]
 pub fn replace<T>(dest: &mut T, mut src: T) -> T {
     swap(dest, &mut src);
     src