Implement review suggestions
This commit is contained in:
parent
bb2c14e92b
commit
5e10b039a3
@ -27,7 +27,7 @@
|
|||||||
use rustc_middle::ty::{self, Ty, TyS};
|
use rustc_middle::ty::{self, Ty, TyS};
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
use rustc_span::symbol::{Ident, Symbol};
|
use rustc_span::symbol::{sym, Ident, Symbol};
|
||||||
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||||
use std::iter::{once, Iterator};
|
use std::iter::{once, Iterator};
|
||||||
use std::mem;
|
use std::mem;
|
||||||
@ -2442,7 +2442,7 @@ fn check_needless_collect_indirect_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCo
|
|||||||
if let Some(ref generic_args) = method_name.args;
|
if let Some(ref generic_args) = method_name.args;
|
||||||
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
if let Some(GenericArg::Type(ref ty)) = generic_args.args.get(0);
|
||||||
if let ty = cx.typeck_results().node_type(ty.hir_id);
|
if let ty = cx.typeck_results().node_type(ty.hir_id);
|
||||||
if is_type_diagnostic_item(cx, ty, sym!(vec_type)) ||
|
if is_type_diagnostic_item(cx, ty, sym::vec_type) ||
|
||||||
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
is_type_diagnostic_item(cx, ty, sym!(vecdeque_type)) ||
|
||||||
match_type(cx, ty, &paths::LINKED_LIST);
|
match_type(cx, ty, &paths::LINKED_LIST);
|
||||||
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
|
if let Some(iter_calls) = detect_iter_and_into_iters(block, *ident);
|
||||||
@ -2524,12 +2524,11 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
|
|||||||
if let &[name] = &path.segments;
|
if let &[name] = &path.segments;
|
||||||
if name.ident == self.target;
|
if name.ident == self.target;
|
||||||
then {
|
then {
|
||||||
let into_iter = sym!(into_iter);
|
|
||||||
let len = sym!(len);
|
let len = sym!(len);
|
||||||
let is_empty = sym!(is_empty);
|
let is_empty = sym!(is_empty);
|
||||||
let contains = sym!(contains);
|
let contains = sym!(contains);
|
||||||
match method_name.ident.name {
|
match method_name.ident.name {
|
||||||
name if name == into_iter => self.uses.push(
|
sym::into_iter => self.uses.push(
|
||||||
IterFunction { func: IterFunctionKind::IntoIter, span: expr.span }
|
IterFunction { func: IterFunctionKind::IntoIter, span: expr.span }
|
||||||
),
|
),
|
||||||
name if name == len => self.uses.push(
|
name if name == len => self.uses.push(
|
||||||
|
@ -1,22 +0,0 @@
|
|||||||
// run-rustfix
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
use std::collections::{HashMap, VecDeque};
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let sample = [1; 5];
|
|
||||||
let indirect_iter = sample.iter().collect::<Vec<_>>();
|
|
||||||
indirect_iter.into_iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
|
||||||
let indirect_len = sample.iter().collect::<VecDeque<_>>();
|
|
||||||
indirect_len.len();
|
|
||||||
let indirect_empty = sample.iter().collect::<VecDeque<_>>();
|
|
||||||
indirect_empty.is_empty();
|
|
||||||
let indirect_contains = sample.iter().collect::<VecDeque<_>>();
|
|
||||||
indirect_contains.contains(&&5);
|
|
||||||
let indirect_negative = sample.iter().collect::<Vec<_>>();
|
|
||||||
indirect_negative.len();
|
|
||||||
indirect_negative
|
|
||||||
.into_iter()
|
|
||||||
.map(|x| (*x, *x + 1))
|
|
||||||
.collect::<HashMap<_, _>>();
|
|
||||||
}
|
|
@ -1,6 +1,3 @@
|
|||||||
// run-rustfix
|
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
use std::collections::{HashMap, VecDeque};
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: avoid using `collect()` when not needed
|
error: avoid using `collect()` when not needed
|
||||||
--> $DIR/needless_collect_indirect.rs:8:5
|
--> $DIR/needless_collect_indirect.rs:5:5
|
||||||
|
|
|
|
||||||
LL | / let indirect_iter = sample.iter().collect::<Vec<_>>();
|
LL | / let indirect_iter = sample.iter().collect::<Vec<_>>();
|
||||||
LL | | indirect_iter.into_iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|
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<_, _>>();
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: avoid using `collect()` when not needed
|
error: avoid using `collect()` when not needed
|
||||||
--> $DIR/needless_collect_indirect.rs:10:5
|
--> $DIR/needless_collect_indirect.rs:7:5
|
||||||
|
|
|
|
||||||
LL | / let indirect_len = sample.iter().collect::<VecDeque<_>>();
|
LL | / let indirect_len = sample.iter().collect::<VecDeque<_>>();
|
||||||
LL | | indirect_len.len();
|
LL | | indirect_len.len();
|
||||||
@ -26,7 +26,7 @@ LL | sample.iter().count();
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: avoid using `collect()` when not needed
|
error: avoid using `collect()` when not needed
|
||||||
--> $DIR/needless_collect_indirect.rs:12:5
|
--> $DIR/needless_collect_indirect.rs:9:5
|
||||||
|
|
|
|
||||||
LL | / let indirect_empty = sample.iter().collect::<VecDeque<_>>();
|
LL | / let indirect_empty = sample.iter().collect::<VecDeque<_>>();
|
||||||
LL | | indirect_empty.is_empty();
|
LL | | indirect_empty.is_empty();
|
||||||
@ -39,7 +39,7 @@ LL | sample.iter().next().is_none();
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: avoid using `collect()` when not needed
|
error: avoid using `collect()` when not needed
|
||||||
--> $DIR/needless_collect_indirect.rs:14:5
|
--> $DIR/needless_collect_indirect.rs:11:5
|
||||||
|
|
|
|
||||||
LL | / let indirect_contains = sample.iter().collect::<VecDeque<_>>();
|
LL | / let indirect_contains = sample.iter().collect::<VecDeque<_>>();
|
||||||
LL | | indirect_contains.contains(&&5);
|
LL | | indirect_contains.contains(&&5);
|
||||||
|
Loading…
Reference in New Issue
Block a user