@@ -2,7 +2,7 @@ use clippy_config::Conf;
22use  clippy_utils:: diagnostics:: span_lint_and_then; 
33use  clippy_utils:: is_from_proc_macro; 
44use  clippy_utils:: msrvs:: { self ,  Msrv } ; 
5- use  clippy_utils:: source:: SpanRangeExt ; 
5+ use  clippy_utils:: source:: snippet_opt ; 
66use  hir:: def_id:: DefId ; 
77use  rustc_errors:: Applicability ; 
88use  rustc_hir as  hir; 
@@ -113,35 +113,18 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
113113            // since this would only require removing a `use` import (which is already linted). 
114114            && !is_numeric_const_path_canonical ( path,  [ * mod_name,  * name] ) 
115115        { 
116-             ( 
117-                 vec ! [ ( expr. span,  format!( "{mod_name}::{name}" ) ) ] , 
118-                 "usage of a legacy numeric constant" , 
119-             ) 
116+             ( format ! ( "{mod_name}::{name}" ) ,  "usage of a legacy numeric constant" ) 
120117        // `<integer>::xxx_value` check 
121118        }  else  if  let  ExprKind :: Call ( func,  [ ] )  = & expr. kind 
122119            && let  ExprKind :: Path ( qpath)  = & func. kind 
123120            && let  QPath :: TypeRelative ( ty,  last_segment)  = qpath
124121            && let  Some ( def_id)  = cx. qpath_res ( qpath,  func. hir_id ) . opt_def_id ( ) 
125122            && is_integer_method ( cx,  def_id) 
123+             && let  Some ( mod_name)  = snippet_opt ( cx,  ty. span ) 
124+             && ty. span . eq_ctxt ( last_segment. ident . span ) 
126125        { 
127-             let  mut  sugg = vec ! [ 
128-                 // Replace the function name up to the end by the constant name 
129-                 ( 
130-                     last_segment. ident. span. to( expr. span. shrink_to_hi( ) ) , 
131-                     last_segment. ident. name. as_str( ) [ ..=2 ] . to_ascii_uppercase( ) , 
132-                 ) , 
133-             ] ; 
134-             let  before_span = expr. span . shrink_to_lo ( ) . until ( ty. span ) ; 
135-             if  !before_span. is_empty ( )  { 
136-                 // Remove everything before the type name 
137-                 sugg. push ( ( before_span,  String :: new ( ) ) ) ; 
138-             } 
139-             // Use `::` between the type name and the constant 
140-             let  between_span = ty. span . shrink_to_hi ( ) . until ( last_segment. ident . span ) ; 
141-             if  !between_span. check_source_text ( cx,  |s| s == "::" )  { 
142-                 sugg. push ( ( between_span,  String :: from ( "::" ) ) ) ; 
143-             } 
144-             ( sugg,  "usage of a legacy numeric method" ) 
126+             let  name = last_segment. ident . name . as_str ( ) [ ..=2 ] . to_ascii_uppercase ( ) ; 
127+             ( format ! ( "{mod_name}::{name}" ) ,  "usage of a legacy numeric method" ) 
145128        }  else  { 
146129            return ; 
147130        } ; 
@@ -151,7 +134,8 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
151134            && !is_from_proc_macro ( cx,  expr) 
152135        { 
153136            span_lint_and_then ( cx,  LEGACY_NUMERIC_CONSTANTS ,  expr. span ,  msg,  |diag| { 
154-                 diag. multipart_suggestion_verbose ( 
137+                 diag. span_suggestion_verbose ( 
138+                     expr. span , 
155139                    "use the associated constant instead" , 
156140                    sugg, 
157141                    Applicability :: MaybeIncorrect , 
0 commit comments