-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
mem_replace_with_default
wrongly unmangles macros when giving suggestions.
Reproducer
I tried this code:
fn dest_from_macro() {
macro_rules! borrow_mut {
($x:expr) => {
&mut $x
};
}
let mut text = String::from("foo");
let replaced = std::mem::replace(borrow_mut!(text), String::default());
}
I expected to see this happen:
LL | let replaced = std::mem::replace(borrow_mut!(text), String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(borrow_mut!(text))`
Instead, this happened:
LL | let replaced = std::mem::replace(borrow_mut!(text), String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(&mut $x)`
Version
rustc 1.92.0-nightly (4645a7988 2025-09-17)
binary: rustc
commit-hash: 4645a7988177c286f61609cc667ecae4c571a2e8
commit-date: 2025-09-17
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.1
Additional Labels
@rustbot claim
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing