1
- use crate :: utils:: { snippet, span_lint_and_note} ;
1
+ use crate :: utils:: { snippet, span_lint_and_note, match_path_ast , paths } ;
2
2
use if_chain:: if_chain;
3
3
use rustc_ast:: ast:: { BindingMode , Block , ExprKind , Mutability , PatKind , StmtKind } ;
4
4
use rustc_lint:: { EarlyContext , EarlyLintPass } ;
@@ -38,14 +38,10 @@ declare_clippy_lint! {
38
38
39
39
declare_lint_pass ! ( FieldReassignWithDefault => [ FIELD_REASSIGN_WITH_DEFAULT ] ) ;
40
40
41
- /// The token for the Default -trait.
42
- const DEFAULT_TRAIT_TOKEN : & str = "Default" ;
43
- const DEFAULT_FUNC_TOKEN : & str = "default" ;
44
-
45
41
impl EarlyLintPass for FieldReassignWithDefault {
46
42
fn check_block ( & mut self , cx : & EarlyContext < ' _ > , block : & Block ) {
47
43
// store statement index and name of binding for all statements like
48
- // `let mut < binding> = Default::default();`
44
+ // `let mut binding = Default::default();`
49
45
let binding_statements_using_default: Vec < ( usize , Symbol ) > = block
50
46
. stmts
51
47
. iter ( )
@@ -60,10 +56,8 @@ impl EarlyLintPass for FieldReassignWithDefault {
60
56
if let Some ( ref expr) = local. init;
61
57
if let ExprKind :: Call ( ref fn_expr, _) = & expr. kind;
62
58
if let ExprKind :: Path ( _, path ) = & fn_expr. kind;
63
- if path. segments. len( ) >= 2 ;
64
59
// 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 ) ;
67
61
then {
68
62
Some ( ( idx, binding. name) )
69
63
}
0 commit comments