]> git.lizzy.rs Git - rust.git/commit
Auto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=giraffate
authorbors <bors@rust-lang.org>
Tue, 12 Apr 2022 01:11:54 +0000 (01:11 +0000)
committerbors <bors@rust-lang.org>
Tue, 12 Apr 2022 01:11:54 +0000 (01:11 +0000)
commitbc069efb1fffc180b13f03fbdc2ab483e5bab13b
treefa5a1275f2ef868814a94d4289ed261e76dde2ca
parentdbcd82885f4730077fabd57340d7e297122bc596
parent40224f46c0158ff8bf6657f2272dba9ec2ee96d7
Auto merge of #8688 - kyoto7250:adding_condition_for_map_clone, r=giraffate

adding condition for map_clone message

This PR fixes the message about `map_clone`.

if msrv >= 1.36, the message is correct.

```bash
$ cat main.rs
fn main() {
  let x: Vec<&i32> = vec![&1, &2];
  let y: Vec<_>  = x.iter().map(|i| *i).collect();
  println!("{:?}", y);
}

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `x.iter().copied()`
  |
  = note: `#[warn(clippy::map_clone)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_clone

warning: `test` (build script) generated 1 warning
warning: `test` (bin "test") generated 1 warning (1 duplicate)
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
```

but, if msrv < 1.36, the suggestion is `cloned`, but the message is `copying`.
```bash
$ cat clippy.toml
msrv = "1.35"

$ cargo clippy
warning: you are using an explicit closure for copying elements
 --> main.rs:3:20
  |
3 |   let y: Vec<_>  = x.iter().map(|i| *i).collect();
  |                    ^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `x.iter().cloned()`
```

I think  the separation of messages will make it more user-friendly.

thank you in advance.

changelog: Fixed a message in map_clone.