@@ -48,15 +48,11 @@ impl_lint_pass!(LegacyNumericConstants => [LEGACY_NUMERIC_CONSTANTS]);
48
48
49
49
impl < ' tcx > LateLintPass < ' tcx > for LegacyNumericConstants {
50
50
fn check_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx Item < ' tcx > ) {
51
- let Self { msrv } = self ;
52
-
53
- if !msrv. meets ( NUMERIC_ASSOCIATED_CONSTANTS ) || in_external_macro ( cx. sess ( ) , item. span ) {
54
- return ;
55
- }
56
-
57
51
// Integer modules are "TBD" deprecated, and the contents are too,
58
52
// so lint on the `use` statement directly.
59
53
if let ItemKind :: Use ( path, kind @ ( UseKind :: Single | UseKind :: Glob ) ) = item. kind
54
+ && self . msrv . meets ( NUMERIC_ASSOCIATED_CONSTANTS )
55
+ && !in_external_macro ( cx. sess ( ) , item. span )
60
56
&& let Some ( def_id) = path. res [ 0 ] . opt_def_id ( )
61
57
{
62
58
let module = if is_integer_module ( cx, def_id) {
@@ -103,12 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
103
99
}
104
100
105
101
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx rustc_hir:: Expr < ' tcx > ) {
106
- let Self { msrv } = self ;
107
-
108
- if !msrv. meets ( NUMERIC_ASSOCIATED_CONSTANTS ) || in_external_macro ( cx. sess ( ) , expr. span ) {
109
- return ;
110
- }
111
- let ExprKind :: Path ( qpath) = expr. kind else {
102
+ let ExprKind :: Path ( qpath) = & expr. kind else {
112
103
return ;
113
104
} ;
114
105
@@ -129,10 +120,10 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
129
120
)
130
121
// `<integer>::xxx_value` check
131
122
} else if let QPath :: TypeRelative ( _, last_segment) = qpath
132
- && let Some ( def_id) = cx. qpath_res ( & qpath, expr. hir_id ) . opt_def_id ( )
133
- && is_integer_method ( cx, def_id)
123
+ && let Some ( def_id) = cx. qpath_res ( qpath, expr. hir_id ) . opt_def_id ( )
134
124
&& let Some ( par_expr) = get_parent_expr ( cx, expr)
135
- && let ExprKind :: Call ( _, _) = par_expr. kind
125
+ && let ExprKind :: Call ( _, [ ] ) = par_expr. kind
126
+ && is_integer_method ( cx, def_id)
136
127
{
137
128
let name = last_segment. ident . name . as_str ( ) ;
138
129
@@ -145,19 +136,20 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
145
136
return ;
146
137
} ;
147
138
148
- if is_from_proc_macro ( cx, expr) {
149
- return ;
139
+ if self . msrv . meets ( NUMERIC_ASSOCIATED_CONSTANTS )
140
+ && !in_external_macro ( cx. sess ( ) , expr. span )
141
+ && !is_from_proc_macro ( cx, expr)
142
+ {
143
+ span_lint_hir_and_then ( cx, LEGACY_NUMERIC_CONSTANTS , expr. hir_id , span, msg, |diag| {
144
+ diag. span_suggestion_with_style (
145
+ span,
146
+ "use the associated constant instead" ,
147
+ sugg,
148
+ Applicability :: MaybeIncorrect ,
149
+ SuggestionStyle :: ShowAlways ,
150
+ ) ;
151
+ } ) ;
150
152
}
151
-
152
- span_lint_hir_and_then ( cx, LEGACY_NUMERIC_CONSTANTS , expr. hir_id , span, msg, |diag| {
153
- diag. span_suggestion_with_style (
154
- span,
155
- "use the associated constant instead" ,
156
- sugg,
157
- Applicability :: MaybeIncorrect ,
158
- SuggestionStyle :: ShowAlways ,
159
- ) ;
160
- } ) ;
161
153
}
162
154
163
155
extract_msrv_attr ! ( LateContext ) ;
0 commit comments