Skip to content

Commit 2371879

Browse files
author
Henri Lunnikivi
committed
Simplify using utils
1 parent 99c07e2 commit 2371879

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

clippy_lints/src/field_reassign_with_default.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{snippet, span_lint_and_note};
1+
use crate::utils::{snippet, span_lint_and_note, match_path_ast, paths};
22
use if_chain::if_chain;
33
use rustc_ast::ast::{BindingMode, Block, ExprKind, Mutability, PatKind, StmtKind};
44
use rustc_lint::{EarlyContext, EarlyLintPass};
@@ -38,14 +38,10 @@ declare_clippy_lint! {
3838

3939
declare_lint_pass!(FieldReassignWithDefault => [FIELD_REASSIGN_WITH_DEFAULT]);
4040

41-
/// The token for the Default -trait.
42-
const DEFAULT_TRAIT_TOKEN: &str = "Default";
43-
const DEFAULT_FUNC_TOKEN: &str = "default";
44-
4541
impl EarlyLintPass for FieldReassignWithDefault {
4642
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &Block) {
4743
// store statement index and name of binding for all statements like
48-
// `let mut <binding> = Default::default();`
44+
// `let mut binding = Default::default();`
4945
let binding_statements_using_default: Vec<(usize, Symbol)> = block
5046
.stmts
5147
.iter()
@@ -60,10 +56,8 @@ impl EarlyLintPass for FieldReassignWithDefault {
6056
if let Some(ref expr) = local.init;
6157
if let ExprKind::Call(ref fn_expr, _) = &expr.kind;
6258
if let ExprKind::Path( _, path ) = &fn_expr.kind;
63-
if path.segments.len() >= 2;
6459
// right hand side of assignment is `Default::default`
65-
if path.segments[path.segments.len()-2].ident.to_string() == DEFAULT_TRAIT_TOKEN;
66-
if path.segments.last().unwrap().ident.to_string() == DEFAULT_FUNC_TOKEN;
60+
if match_path_ast(&path, &paths::DEFAULT_TRAIT_METHOD);
6761
then {
6862
Some((idx, binding.name))
6963
}

0 commit comments

Comments
 (0)