1
1
use crate :: utils:: paths;
2
2
use crate :: utils:: {
3
- is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty,
3
+ is_expn_of, last_path_segment, match_def_path, match_function_call, match_type, snippet, span_lint_and_then,
4
+ walk_ptrs_ty,
4
5
} ;
5
6
use if_chain:: if_chain;
6
7
use rustc:: hir:: * ;
@@ -70,19 +71,16 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
70
71
} ) ;
71
72
}
72
73
73
- fn on_argumentv1_new < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr , arms : & ' a [ Arm ] ) -> Option < String > {
74
+ fn on_argumentv1_new < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr , arms : & ' tcx [ Arm ] ) -> Option < String > {
74
75
if_chain ! {
75
76
if let ExprKind :: AddrOf ( _, ref format_args) = expr. kind;
76
77
if let ExprKind :: Array ( ref elems) = arms[ 0 ] . body. kind;
77
78
if elems. len( ) == 1 ;
78
- if let ExprKind :: Call ( ref fun, ref args) = elems[ 0 ] . kind;
79
- if let ExprKind :: Path ( ref qpath) = fun. kind;
80
- if let Some ( did) = resolve_node( cx, qpath, fun. hir_id) . opt_def_id( ) ;
81
- if match_def_path( cx, did, & paths:: FMT_ARGUMENTV1_NEW ) ;
79
+ if let Some ( args) = match_function_call( cx, & elems[ 0 ] , & paths:: FMT_ARGUMENTV1_NEW ) ;
82
80
// matches `core::fmt::Display::fmt`
83
81
if args. len( ) == 2 ;
84
82
if let ExprKind :: Path ( ref qpath) = args[ 1 ] . kind;
85
- if let Some ( did) = resolve_node ( cx , qpath, args[ 1 ] . hir_id) . opt_def_id( ) ;
83
+ if let Some ( did) = cx . tables . qpath_res ( qpath, args[ 1 ] . hir_id) . opt_def_id( ) ;
86
84
if match_def_path( cx, did, & paths:: DISPLAY_FMT_METHOD ) ;
87
85
// check `(arg0,)` in match block
88
86
if let PatKind :: Tuple ( ref pats, None ) = arms[ 0 ] . pat. kind;
@@ -114,11 +112,8 @@ fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arm
114
112
115
113
fn on_new_v1 < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) -> Option < String > {
116
114
if_chain ! {
117
- if let ExprKind :: Call ( ref fun , ref args) = expr. kind ;
115
+ if let Some ( args) = match_function_call ( cx , expr, & paths :: FMT_ARGUMENTS_NEW_V1 ) ;
118
116
if args. len( ) == 2 ;
119
- if let ExprKind :: Path ( ref qpath) = fun. kind;
120
- if let Some ( did) = resolve_node( cx, qpath, fun. hir_id) . opt_def_id( ) ;
121
- if match_def_path( cx, did, & paths:: FMT_ARGUMENTS_NEW_V1 ) ;
122
117
// Argument 1 in `new_v1()`
123
118
if let ExprKind :: AddrOf ( _, ref arr) = args[ 0 ] . kind;
124
119
if let ExprKind :: Array ( ref pieces) = arr. kind;
@@ -144,11 +139,8 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<S
144
139
145
140
fn on_new_v1_fmt < ' a , ' tcx > ( cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) -> Option < String > {
146
141
if_chain ! {
147
- if let ExprKind :: Call ( ref fun , ref args) = expr. kind ;
142
+ if let Some ( args) = match_function_call ( cx , expr, & paths :: FMT_ARGUMENTS_NEW_V1_FORMATTED ) ;
148
143
if args. len( ) == 3 ;
149
- if let ExprKind :: Path ( ref qpath) = fun. kind;
150
- if let Some ( did) = resolve_node( cx, qpath, fun. hir_id) . opt_def_id( ) ;
151
- if match_def_path( cx, did, & paths:: FMT_ARGUMENTS_NEW_V1_FORMATTED ) ;
152
144
if check_unformatted( & args[ 2 ] ) ;
153
145
// Argument 1 in `new_v1_formatted()`
154
146
if let ExprKind :: AddrOf ( _, ref arr) = args[ 0 ] . kind;
0 commit comments