Merge pull request #2975 from aaudiber/lint-identity-into-iter
Lint using identity into_iter conversion
This commit is contained in:
commit
32e4897854
3 changed files with 34 additions and 9 deletions
|
|
@ -5,7 +5,7 @@ use syntax::ast::NodeId;
|
|||
use crate::utils::{in_macro, match_def_path, match_trait_method, same_tys, snippet, span_lint_and_then};
|
||||
use crate::utils::{opt_def_id, paths, resolve_node};
|
||||
|
||||
/// **What it does:** Checks for always-identical `Into`/`From` conversions.
|
||||
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
|
||||
///
|
||||
/// **Why is this bad?** Redundant code.
|
||||
///
|
||||
|
|
@ -19,7 +19,7 @@ use crate::utils::{opt_def_id, paths, resolve_node};
|
|||
declare_clippy_lint! {
|
||||
pub IDENTITY_CONVERSION,
|
||||
complexity,
|
||||
"using always-identical `Into`/`From` conversions"
|
||||
"using always-identical `Into`/`From`/`IntoIter` conversions"
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -67,6 +67,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
|
|||
});
|
||||
}
|
||||
}
|
||||
if match_trait_method(cx, e, &paths::INTO_ITERATOR) && &*name.ident.as_str() == "into_iter" {
|
||||
let a = cx.tables.expr_ty(e);
|
||||
let b = cx.tables.expr_ty(&args[0]);
|
||||
if same_tys(cx, a, b) {
|
||||
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
|
||||
span_lint_and_then(cx, IDENTITY_CONVERSION, e.span, "identical conversion", |db| {
|
||||
db.span_suggestion(e.span, "consider removing `.into_iter()`", sugg);
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
ExprKind::Call(ref path, ref args) => if let ExprKind::Path(ref qpath) = path.node {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue