Skip to content

Commit 6a59390

Browse files
committed
Filter parts by which are nonempty so we don't make vacuous suggestions
1 parent 4b7a835 commit 6a59390

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

clippy_lints/src/methods/map_with_unused_argument_over_ranges.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ pub(super) fn check(
100100
return;
101101
}
102102

103+
// We need to provide nonempty parts to diag.multipart_suggestion so we
104+
// collate all our parts here and then remove those that are empty.
105+
let parts = [
106+
(
107+
receiver.span.to(method_call_span),
108+
format!("std::iter::{method_to_use_name}"),
109+
),
110+
new_span,
111+
(
112+
ex.span.shrink_to_hi(),
113+
if use_take {
114+
format!(".take({count})")
115+
} else {
116+
String::new()
117+
},
118+
),
119+
]
120+
.into_iter()
121+
.filter(|part| !(part.0.is_empty() && part.1.is_empty()))
122+
.collect();
123+
103124
span_lint_and_then(
104125
cx,
105126
MAP_WITH_UNUSED_ARGUMENT_OVER_RANGES,
@@ -112,21 +133,7 @@ pub(super) fn check(
112133
} else {
113134
format!("remove the explicit range and use `{method_to_use_name}`")
114135
},
115-
vec![
116-
(
117-
receiver.span.to(method_call_span),
118-
format!("std::iter::{method_to_use_name}"),
119-
),
120-
new_span,
121-
(
122-
ex.span.shrink_to_hi(),
123-
if use_take {
124-
format!(".take({count})")
125-
} else {
126-
String::new()
127-
},
128-
),
129-
],
136+
parts,
130137
applicability,
131138
);
132139
},

0 commit comments

Comments
 (0)