Skip to content

Commit bc069ef

Browse files
committed
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.
2 parents dbcd828 + 40224f4 commit bc069ef

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

clippy_lints/src/map_clone.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,11 @@ fn lint_needless_cloning(cx: &LateContext<'_>, root: Span, receiver: Span) {
143143
impl MapClone {
144144
fn lint_explicit_closure(&self, cx: &LateContext<'_>, replace: Span, root: Span, is_copy: bool) {
145145
let mut applicability = Applicability::MachineApplicable;
146-
let message = if is_copy {
147-
"you are using an explicit closure for copying elements"
148-
} else {
149-
"you are using an explicit closure for cloning elements"
150-
};
151-
let sugg_method = if is_copy && meets_msrv(self.msrv.as_ref(), &msrvs::ITERATOR_COPIED) {
152-
"copied"
146+
147+
let (message, sugg_method) = if is_copy && meets_msrv(self.msrv.as_ref(), &msrvs::ITERATOR_COPIED) {
148+
("you are using an explicit closure for copying elements", "copied")
153149
} else {
154-
"cloned"
150+
("you are using an explicit closure for cloning elements", "cloned")
155151
};
156152

157153
span_lint_and_sugg(

tests/ui-toml/min_rust_version/min_rust_version.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: you are using an explicit closure for copying elements
1+
error: you are using an explicit closure for cloning elements
22
--> $DIR/min_rust_version.rs:74:26
33
|
44
LL | let _: Option<u64> = Some(&16).map(|b| *b);

0 commit comments

Comments
 (0)