Closed
Description
Summary
Similar to how some people prefer to use the fully qualified Arc::clone(&foo)
rather than foo.clone()
for readability, people may also prefer foo.map(Arc::clone)
rather than foo.cloned()
to be more explicit that the Arc
is being cloned. I think that the map_clone
lint should not trigger for foo.map(Arc::clone)
or for foo.map(Rc::clone)
.
This is of course subjective, but it would be a subjective choice to not show a warning, which I think is nicer.
Lint Name
map_clone
Reproducer
I tried this code:
use std::sync::Arc;
struct Foo;
fn main() {
let x = Arc::new(Foo);
let y = Some(&x);
let _z = y.map(Arc::clone);
}
I saw this happen:
warning: you are explicitly cloning with `.map()`
--> src/main.rs:8:14
|
8 | let _z = y.map(Arc::clone);
| ^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `y.cloned()`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
= note: `#[warn(clippy::map_clone)]` on by default
I expected to see this happen:
No lint.
Version
rustc 1.79.0-nightly (1388d7a06 2024-03-20)
binary: rustc
commit-hash: 1388d7a069d872bcfe5e5dd97ef61fa0a586fac0
commit-date: 2024-03-20
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2
Additional Labels
No response