Skip to content

Commit

Permalink
Lint must_use on mem::replace
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
cuviper committed Apr 17, 2020
1 parent 8d67f57 commit 7c4ca59
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/libcore/mem/mod.rs
Expand Up @@ -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
Expand Down

0 comments on commit 7c4ca59

Please sign in to comment.