Skip to content

Commit b0dcb86

Browse files
committed
Move needless_collect into the methods lint pass
1 parent 213003b commit b0dcb86

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
237237
crate::loops::MANUAL_MEMCPY_INFO,
238238
crate::loops::MISSING_SPIN_LOOP_INFO,
239239
crate::loops::MUT_RANGE_BOUND_INFO,
240-
crate::loops::NEEDLESS_COLLECT_INFO,
241240
crate::loops::NEEDLESS_RANGE_LOOP_INFO,
242241
crate::loops::NEVER_LOOP_INFO,
243242
crate::loops::SAME_ITEM_PUSH_INFO,
@@ -346,6 +345,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
346345
crate::methods::MAP_UNWRAP_OR_INFO,
347346
crate::methods::MUT_MUTEX_LOCK_INFO,
348347
crate::methods::NAIVE_BYTECOUNT_INFO,
348+
crate::methods::NEEDLESS_COLLECT_INFO,
349349
crate::methods::NEEDLESS_OPTION_AS_DEREF_INFO,
350350
crate::methods::NEEDLESS_OPTION_TAKE_INFO,
351351
crate::methods::NEEDLESS_SPLITN_INFO,

clippy_lints/src/loops/mod.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mod manual_flatten;
99
mod manual_memcpy;
1010
mod missing_spin_loop;
1111
mod mut_range_bound;
12-
mod needless_collect;
1312
mod needless_range_loop;
1413
mod never_loop;
1514
mod same_item_push;
@@ -205,28 +204,6 @@ declare_clippy_lint! {
205204
"`loop { if let { ... } else break }`, which can be written as a `while let` loop"
206205
}
207206

208-
declare_clippy_lint! {
209-
/// ### What it does
210-
/// Checks for functions collecting an iterator when collect
211-
/// is not needed.
212-
///
213-
/// ### Why is this bad?
214-
/// `collect` causes the allocation of a new data structure,
215-
/// when this allocation may not be needed.
216-
///
217-
/// ### Example
218-
/// ```rust
219-
/// # let iterator = vec![1].into_iter();
220-
/// let len = iterator.clone().collect::<Vec<_>>().len();
221-
/// // should be
222-
/// let len = iterator.count();
223-
/// ```
224-
#[clippy::version = "1.30.0"]
225-
pub NEEDLESS_COLLECT,
226-
nursery,
227-
"collecting an iterator when collect is not needed"
228-
}
229-
230207
declare_clippy_lint! {
231208
/// ### What it does
232209
/// Checks `for` loops over slices with an explicit counter
@@ -605,7 +582,6 @@ declare_lint_pass!(Loops => [
605582
EXPLICIT_INTO_ITER_LOOP,
606583
ITER_NEXT_LOOP,
607584
WHILE_LET_LOOP,
608-
NEEDLESS_COLLECT,
609585
EXPLICIT_COUNTER_LOOP,
610586
EMPTY_LOOP,
611587
WHILE_LET_ON_ITERATOR,
@@ -667,8 +643,6 @@ impl<'tcx> LateLintPass<'tcx> for Loops {
667643
while_immutable_condition::check(cx, condition, body);
668644
missing_spin_loop::check(cx, condition, body);
669645
}
670-
671-
needless_collect::check(expr, cx);
672646
}
673647
}
674648

clippy_lints/src/methods/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ mod map_flatten;
5454
mod map_identity;
5555
mod map_unwrap_or;
5656
mod mut_mutex_lock;
57+
mod needless_collect;
5758
mod needless_option_as_deref;
5859
mod needless_option_take;
5960
mod no_effect_replace;
@@ -3141,6 +3142,28 @@ declare_clippy_lint! {
31413142
"jumping to the start of stream using `seek` method"
31423143
}
31433144

3145+
declare_clippy_lint! {
3146+
/// ### What it does
3147+
/// Checks for functions collecting an iterator when collect
3148+
/// is not needed.
3149+
///
3150+
/// ### Why is this bad?
3151+
/// `collect` causes the allocation of a new data structure,
3152+
/// when this allocation may not be needed.
3153+
///
3154+
/// ### Example
3155+
/// ```rust
3156+
/// # let iterator = vec![1].into_iter();
3157+
/// let len = iterator.clone().collect::<Vec<_>>().len();
3158+
/// // should be
3159+
/// let len = iterator.count();
3160+
/// ```
3161+
#[clippy::version = "1.30.0"]
3162+
pub NEEDLESS_COLLECT,
3163+
nursery,
3164+
"collecting an iterator when collect is not needed"
3165+
}
3166+
31443167
pub struct Methods {
31453168
avoid_breaking_exported_api: bool,
31463169
msrv: Option<RustcVersion>,
@@ -3267,6 +3290,7 @@ impl_lint_pass!(Methods => [
32673290
ITER_KV_MAP,
32683291
SEEK_FROM_CURRENT,
32693292
SEEK_TO_START_INSTEAD_OF_REWIND,
3293+
NEEDLESS_COLLECT,
32703294
]);
32713295

32723296
/// Extracts a method call name, args, and `Span` of the method name.
@@ -3317,6 +3341,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
33173341
},
33183342
_ => (),
33193343
}
3344+
3345+
needless_collect::check(expr, cx);
33203346
}
33213347

33223348
#[allow(clippy::too_many_lines)]

0 commit comments

Comments
 (0)