Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mem::replace warning #124

Merged
merged 2 commits into from
May 3, 2020
Merged

Fix mem::replace warning #124

merged 2 commits into from
May 3, 2020

Conversation

joshleeb
Copy link
Contributor

@joshleeb joshleeb commented May 3, 2020

This PR fixes the following warning caused by not using the returned
value from mem::replace.

warning: unused return value of `std::mem::replace` that must be used
--> mockall_derive/src/lib.rs:519:21
    |
519 |                     mem::replace(bt, new_bt);
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
    = note: if you don't need the old value, you can
    just assign the new value directly

warning: 1 warning emitted

This PR fixes the following warning caused by not using the returned
value from `mem::replace`.

```
warning: unused return value of `std::mem::replace` that must be used
--> mockall_derive/src/lib.rs:519:21
    |
519 |                     mem::replace(bt, new_bt);
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(unused_must_use)]` on by default
    = note: if you don't need the old value, you can
    just assign the new value directly

warning: 1 warning emitted
```
@joshleeb joshleeb requested a review from asomers as a code owner May 3, 2020 13:26
@@ -516,7 +516,7 @@ fn supersuperfy(original: &Type, levels: i32) -> Type {
Type::BareFn(bfn) => {
if let ReturnType::Type(_, ref mut bt) = bfn.output {
let new_bt = Box::new(supersuperfy(bt.as_ref(), levels));
mem::replace(bt, new_bt);
let _ = mem::replace(bt, new_bt);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could instead replace this with mem::swap if you prefer 👍 but imho thought this was a bit more explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - should've seen that we could get rid of mem::replace entirely

@asomers
Copy link
Owner

asomers commented May 3, 2020

Thanks! But I haven't noticed this warning before. Is it a new one? What rustc version are you using?

@joshleeb
Copy link
Contributor Author

joshleeb commented May 3, 2020

What rustc version are you using?

$ rustc --version
rustc 1.45.0-nightly (7ced01a73 2020-04-30)

Warning displayed when running cargo check.

@asomers asomers merged commit 057cacf into asomers:master May 3, 2020
@joshleeb joshleeb deleted the fix-mem-replace-warn branch May 3, 2020 14:31
asomers added a commit that referenced this pull request May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants