-
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 thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
swap_with_temporary
fires when you swap
(the deref'd object behind) a MutexGuard
with a stack variable as it incorrectly thinks the MutexGuard
is a temporary.
Lint Name
swap_with_temporary
Reproducer
We have a bunch of cases like the following which now trigger the lint:
struct A {
thing: Mutex<Vec<u8>>,
}
impl A {
fn a(&self) {
let new_vec = vec![42];
std::mem::swap(&mut self.thing.lock().unwrap(), new_vec);
for v in new_vec {
// Do something with v
}
}
Version
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way