Skip to content

Commit 5e10b03

Browse files
committed
Implement review suggestions
1 parent bb2c14e commit 5e10b03

File tree

4 files changed

+7
-33
lines changed

4 files changed

+7
-33
lines changed

clippy_lints/src/loops.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::middle::region;
2727
use rustc_middle::ty::{self, Ty, TyS};
2828
use rustc_session::{declare_lint_pass, declare_tool_lint};
2929
use rustc_span::source_map::Span;
30-
use rustc_span::symbol::{Ident, Symbol};
30+
use rustc_span::symbol::{sym, Ident, Symbol};
3131
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
3232
use std::iter::{once, Iterator};
3333
use std::mem;
@@ -2442,7 +2442,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
24422442
if let Some(ref generic_args) = method_name.args;
24432443
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
24442444
if let ty = cx.typeck_results().node_type(ty.hir_id);
2445-
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
2445+
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
24462446
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
24472447
match_type(cx, ty, &paths::LINKED_LIST);
24482448
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
@@ -2524,12 +2524,11 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor {
25242524
if let &[name] = &path.segments;
25252525
if name.ident == self.target;
25262526
then {
2527-
let into_iter = sym!(into_iter);
25282527
let len = sym!(len);
25292528
let is_empty = sym!(is_empty);
25302529
let contains = sym!(contains);
25312530
match method_name.ident.name {
2532-
name if name == into_iter => self.uses.push(
2531+
sym::into_iter => self.uses.push(
25332532
IterFunction { func: IterFunctionKind::IntoIter, span: expr.span }
25342533
),
25352534
name if name == len => self.uses.push(

tests/ui/needless_collect_indirect.fixed

-22
This file was deleted.

tests/ui/needless_collect_indirect.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// run-rustfix
2-
3-
#[allow(unused)]
41
use std::collections::{HashMap, VecDeque};
52

63
fn main() {

tests/ui/needless_collect_indirect.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: avoid using `collect()` when not needed
2-
--> $DIR/needless_collect_indirect.rs:8:5
2+
--> $DIR/needless_collect_indirect.rs:5:5
33
|
44
LL | / let indirect_iter = sample.iter().collect::<Vec<_>>();
55
LL | | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
@@ -13,7 +13,7 @@ LL | sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
1313
|
1414

1515
error: avoid using `collect()` when not needed
16-
--> $DIR/needless_collect_indirect.rs:10:5
16+
--> $DIR/needless_collect_indirect.rs:7:5
1717
|
1818
LL | / let indirect_len = sample.iter().collect::<VecDeque<_>>();
1919
LL | | indirect_len.len();
@@ -26,7 +26,7 @@ LL | sample.iter().count();
2626
|
2727

2828
error: avoid using `collect()` when not needed
29-
--> $DIR/needless_collect_indirect.rs:12:5
29+
--> $DIR/needless_collect_indirect.rs:9:5
3030
|
3131
LL | / let indirect_empty = sample.iter().collect::<VecDeque<_>>();
3232
LL | | indirect_empty.is_empty();
@@ -39,7 +39,7 @@ LL | sample.iter().next().is_none();
3939
|
4040

4141
error: avoid using `collect()` when not needed
42-
--> $DIR/needless_collect_indirect.rs:14:5
42+
--> $DIR/needless_collect_indirect.rs:11:5
4343
|
4444
LL | / let indirect_contains = sample.iter().collect::<VecDeque<_>>();
4545
LL | | indirect_contains.contains(&&5);

0 commit comments

Comments
 (0)