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

assigning_clones: suggested code contains expanded macro #12776

Closed
mistydemeo opened this issue May 7, 2024 · 0 comments · Fixed by #12783
Closed

assigning_clones: suggested code contains expanded macro #12776

mistydemeo opened this issue May 7, 2024 · 0 comments · Fixed by #12783
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@mistydemeo
Copy link

Summary

The new assigning_clones lint is producing wrong output when the assignment is a macro call. The suggested code is using the expanded macro instead of the macro itself.

Reproducer

I tried this code:

let mut s = String::new().clone();
s = format!("{} {}", "hello", "world").to_owned();

I expected to see this happen:

A lint output that retains the format!() call.

Instead, this happened:

warning: assigning the result of `ToOwned::to_owned()` may be inefficient
 --> src/main.rs:3:5
  |
3 |     s = format!("{} {}", "hello", "world").to_owned();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones
  = note: `#[warn(clippy::assigning_clones)]` on by default
help: use `clone_into()`
  |
3 ~     {
4 +         let res = $crate::fmt::format($crate::__export::format_args!($($arg)*));
5 +         res
6 ~     }.clone_into(&mut s);

Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2

Additional Labels

No response

@mistydemeo mistydemeo added the C-bug Category: Clippy is not doing the correct thing label May 7, 2024
@y21 y21 added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label May 7, 2024
@mistydemeo mistydemeo changed the title assigning_clones: suggested code is assigning_clones: suggested code contains expanded macro May 7, 2024
@bors bors closed this as completed in baf2a23 May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants