1- use crate :: utils:: { snippet, span_lint_and_note} ;
1+ use crate :: utils:: { snippet, span_lint_and_note, match_path_ast , paths } ;
22use if_chain:: if_chain;
33use rustc_ast:: ast:: { BindingMode , Block , ExprKind , Mutability , PatKind , StmtKind } ;
44use rustc_lint:: { EarlyContext , EarlyLintPass } ;
@@ -38,14 +38,10 @@ declare_clippy_lint! {
3838
3939declare_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-
4541impl 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