map_clone: make lint adhere to lint message convention

This commit is contained in:
Matthias Krüger 2020-08-11 11:53:21 +02:00
parent c0a9d64818
commit ac194cafc1
2 changed files with 18 additions and 18 deletions

View File

@ -111,8 +111,8 @@ fn lint_needless_cloning(cx: &LateContext<'_>, root: Span, receiver: Span) {
cx, cx,
MAP_CLONE, MAP_CLONE,
root.trim_start(receiver).unwrap(), root.trim_start(receiver).unwrap(),
"You are needlessly cloning iterator elements", "you are needlessly cloning iterator elements",
"Remove the `map` call", "remove the `map` call",
String::new(), String::new(),
Applicability::MachineApplicable, Applicability::MachineApplicable,
) )
@ -125,8 +125,8 @@ fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) {
cx, cx,
MAP_CLONE, MAP_CLONE,
replace, replace,
"You are using an explicit closure for copying elements", "you are using an explicit closure for copying elements",
"Consider calling the dedicated `copied` method", "consider calling the dedicated `copied` method",
format!( format!(
"{}.copied()", "{}.copied()",
snippet_with_applicability(cx, root, "..", &mut applicability) snippet_with_applicability(cx, root, "..", &mut applicability)
@ -138,8 +138,8 @@ fn lint(cx: &LateContext<'_>, replace: Span, root: Span, copied: bool) {
cx, cx,
MAP_CLONE, MAP_CLONE,
replace, replace,
"You are using an explicit closure for cloning elements", "you are using an explicit closure for cloning elements",
"Consider calling the dedicated `cloned` method", "consider calling the dedicated `cloned` method",
format!( format!(
"{}.cloned()", "{}.cloned()",
snippet_with_applicability(cx, root, "..", &mut applicability) snippet_with_applicability(cx, root, "..", &mut applicability)

View File

@ -1,40 +1,40 @@
error: You are using an explicit closure for copying elements error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:10:22 --> $DIR/map_clone.rs:10:22
| |
LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect(); LL | let _: Vec<i8> = vec![5_i8; 6].iter().map(|x| *x).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![5_i8; 6].iter().copied()`
| |
= note: `-D clippy::map-clone` implied by `-D warnings` = note: `-D clippy::map-clone` implied by `-D warnings`
error: You are using an explicit closure for cloning elements error: you are using an explicit closure for cloning elements
--> $DIR/map_clone.rs:11:26 --> $DIR/map_clone.rs:11:26
| |
LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect(); LL | let _: Vec<String> = vec![String::new()].iter().map(|x| x.clone()).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `cloned` method: `vec![String::new()].iter().cloned()`
error: You are using an explicit closure for copying elements error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:12:23 --> $DIR/map_clone.rs:12:23
| |
LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect(); LL | let _: Vec<u32> = vec![42, 43].iter().map(|&x| x).collect();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `vec![42, 43].iter().copied()`
error: You are using an explicit closure for copying elements error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:14:26 --> $DIR/map_clone.rs:14:26
| |
LL | let _: Option<u64> = Some(&16).map(|b| *b); LL | let _: Option<u64> = Some(&16).map(|b| *b);
| ^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `copied` method: `Some(&16).copied()` | ^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&16).copied()`
error: You are using an explicit closure for copying elements error: you are using an explicit closure for copying elements
--> $DIR/map_clone.rs:15:25 --> $DIR/map_clone.rs:15:25
| |
LL | let _: Option<u8> = Some(&1).map(|x| x.clone()); LL | let _: Option<u8> = Some(&1).map(|x| x.clone());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: Consider calling the dedicated `copied` method: `Some(&1).copied()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider calling the dedicated `copied` method: `Some(&1).copied()`
error: You are needlessly cloning iterator elements error: you are needlessly cloning iterator elements
--> $DIR/map_clone.rs:26:29 --> $DIR/map_clone.rs:26:29
| |
LL | let _ = std::env::args().map(|v| v.clone()); LL | let _ = std::env::args().map(|v| v.clone());
| ^^^^^^^^^^^^^^^^^^^ help: Remove the `map` call | ^^^^^^^^^^^^^^^^^^^ help: remove the `map` call
error: aborting due to 6 previous errors error: aborting due to 6 previous errors