@@ -2,7 +2,7 @@ use clippy_config::Conf;
2
2
use clippy_utils:: diagnostics:: span_lint_and_then;
3
3
use clippy_utils:: is_from_proc_macro;
4
4
use clippy_utils:: msrvs:: { self , Msrv } ;
5
- use clippy_utils:: source:: SpanRangeExt ;
5
+ use clippy_utils:: source:: snippet_opt ;
6
6
use hir:: def_id:: DefId ;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_hir as hir;
@@ -113,35 +113,18 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
113
113
// since this would only require removing a `use` import (which is already linted).
114
114
&& !is_numeric_const_path_canonical ( path, [ * mod_name, * name] )
115
115
{
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" )
120
117
// `<integer>::xxx_value` check
121
118
} else if let ExprKind :: Call ( func, [ ] ) = & expr. kind
122
119
&& let ExprKind :: Path ( qpath) = & func. kind
123
120
&& let QPath :: TypeRelative ( ty, last_segment) = qpath
124
121
&& let Some ( def_id) = cx. qpath_res ( qpath, func. hir_id ) . opt_def_id ( )
125
122
&& 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 )
126
125
{
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" )
145
128
} else {
146
129
return ;
147
130
} ;
@@ -151,7 +134,8 @@ impl<'tcx> LateLintPass<'tcx> for LegacyNumericConstants {
151
134
&& !is_from_proc_macro ( cx, expr)
152
135
{
153
136
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 ,
155
139
"use the associated constant instead" ,
156
140
sugg,
157
141
Applicability :: MaybeIncorrect ,
0 commit comments