@@ -48,15 +48,11 @@ impl_lint_pass!(LegacyNumericConstants => [LEGACY_NUMERIC_CONSTANTS]);
4848
4949impl < ' tcx > LateLintPass < ' tcx > for LegacyNumericConstants {
5050 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-
5751 // Integer modules are "TBD" deprecated, and the contents are too,
5852 // so lint on the `use` statement directly.
5953 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 )
6056 && let Some ( def_id) = path. res [ 0 ] . opt_def_id ( )
6157 {
6258 let module = if is_integer_module ( cx, def_id) {
@@ -103,12 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
10399 }
104100
105101 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 {
112103 return ;
113104 } ;
114105
@@ -129,10 +120,10 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
129120 )
130121 // `<integer>::xxx_value` check
131122 } 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 ( )
134124 && 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)
136127 {
137128 let name = last_segment. ident . name . as_str ( ) ;
138129
@@ -145,19 +136,20 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
145136 return ;
146137 } ;
147138
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+ } ) ;
150152 }
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- } ) ;
161153 }
162154
163155 extract_msrv_attr ! ( LateContext ) ;
0 commit comments