1
1
use clippy_config:: Conf ;
2
2
use clippy_utils:: diagnostics:: span_lint_and_then;
3
+ use clippy_utils:: is_from_proc_macro;
3
4
use clippy_utils:: msrvs:: { self , Msrv } ;
4
- use clippy_utils:: { get_parent_expr, is_from_proc_macro} ;
5
5
use hir:: def_id:: DefId ;
6
6
use rustc_errors:: Applicability ;
7
7
use rustc_hir as hir;
@@ -102,16 +102,12 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
102
102
}
103
103
104
104
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
105
- let ExprKind :: Path ( qpath) = & expr. kind else {
106
- return ;
107
- } ;
108
-
109
105
// `std::<integer>::<CONST>` check
110
- let ( span, sugg, msg) = if let QPath :: Resolved ( None , path) = qpath
106
+ let ( span, sugg, msg) = if let ExprKind :: Path ( qpath) = & expr. kind
107
+ && let QPath :: Resolved ( None , path) = qpath
111
108
&& let Some ( def_id) = path. res . opt_def_id ( )
112
109
&& is_numeric_const ( cx, def_id)
113
- && let def_path = cx. get_def_path ( def_id)
114
- && let [ .., mod_name, name] = & * def_path
110
+ && let [ .., mod_name, name] = & * cx. get_def_path ( def_id)
115
111
// Skip linting if this usage looks identical to the associated constant,
116
112
// since this would only require removing a `use` import (which is already linted).
117
113
&& !is_numeric_const_path_canonical ( path, [ * mod_name, * name] )
@@ -122,16 +118,16 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
122
118
"usage of a legacy numeric constant" ,
123
119
)
124
120
// `<integer>::xxx_value` check
125
- } else if let QPath :: TypeRelative ( mod_path , last_segment ) = qpath
126
- && let Some ( def_id ) = cx . qpath_res ( qpath , expr . hir_id ) . opt_def_id ( )
127
- && let Some ( par_expr ) = get_parent_expr ( cx , expr )
128
- && let ExprKind :: Call ( _ , [ ] ) = par_expr . kind
121
+ } else if let ExprKind :: Call ( func , [ ] ) = & expr . kind
122
+ && let ExprKind :: Path ( qpath ) = & func . kind
123
+ && let QPath :: TypeRelative ( ty , last_segment ) = qpath
124
+ && let Some ( def_id ) = cx . qpath_res ( qpath , func . hir_id ) . opt_def_id ( )
129
125
&& is_integer_method ( cx, def_id)
130
126
{
131
127
let name = last_segment. ident . name . as_str ( ) ;
132
- let mod_name = clippy_utils:: source:: snippet ( cx, mod_path . span , "_" ) ;
128
+ let mod_name = clippy_utils:: source:: snippet ( cx, ty . span , "_" ) ;
133
129
(
134
- par_expr . span ,
130
+ expr . span ,
135
131
format ! ( "{}::{}" , mod_name, name[ ..=2 ] . to_ascii_uppercase( ) ) ,
136
132
"usage of a legacy numeric method" ,
137
133
)
0 commit comments