@@ -68,7 +68,7 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
68
68
max : u128 ,
69
69
expr : & ' tcx hir:: Expr ,
70
70
parent_expr : & ' tcx hir:: Expr ,
71
- ty : impl std :: fmt :: Debug ,
71
+ ty : & str ,
72
72
) -> bool {
73
73
// We only want to handle exclusive (`..`) ranges,
74
74
// which are represented as `ExprKind::Struct`.
@@ -83,15 +83,15 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
83
83
let mut err = cx. struct_span_lint (
84
84
OVERFLOWING_LITERALS ,
85
85
parent_expr. span ,
86
- & format ! ( "range endpoint is out of range for `{:? }`" , ty) ,
86
+ & format ! ( "range endpoint is out of range for `{}`" , ty) ,
87
87
) ;
88
88
if let Ok ( start) = cx. sess ( ) . source_map ( ) . span_to_snippet ( eps[ 0 ] . span ) {
89
89
use ast:: { LitKind , LitIntType } ;
90
90
// We need to preserve the literal's suffix,
91
91
// as it may determine typing information.
92
92
let suffix = match lit. node {
93
- LitKind :: Int ( _, LitIntType :: Signed ( s) ) => format ! ( "{}" , s) ,
94
- LitKind :: Int ( _, LitIntType :: Unsigned ( s) ) => format ! ( "{}" , s) ,
93
+ LitKind :: Int ( _, LitIntType :: Signed ( s) ) => format ! ( "{}" , s. name_str ( ) ) ,
94
+ LitKind :: Int ( _, LitIntType :: Unsigned ( s) ) => format ! ( "{}" , s. name_str ( ) ) ,
95
95
LitKind :: Int ( _, LitIntType :: Unsuffixed ) => "" . to_owned ( ) ,
96
96
_ => bug ! ( ) ,
97
97
} ;
@@ -161,11 +161,11 @@ fn report_bin_hex_error(
161
161
let ( t, actually) = match ty {
162
162
attr:: IntType :: SignedInt ( t) => {
163
163
let actually = sign_extend ( val, size) as i128 ;
164
- ( format ! ( "{:?}" , t ) , actually. to_string ( ) )
164
+ ( t . name_str ( ) , actually. to_string ( ) )
165
165
}
166
166
attr:: IntType :: UnsignedInt ( t) => {
167
167
let actually = truncate ( val, size) ;
168
- ( format ! ( "{:?}" , t ) , actually. to_string ( ) )
168
+ ( t . name_str ( ) , actually. to_string ( ) )
169
169
}
170
170
} ;
171
171
let mut err = cx. struct_span_lint (
@@ -204,7 +204,7 @@ fn report_bin_hex_error(
204
204
// - `uX` => `uY`
205
205
//
206
206
// No suggestion for: `isize`, `usize`.
207
- fn get_type_suggestion ( t : Ty < ' _ > , val : u128 , negative : bool ) -> Option < String > {
207
+ fn get_type_suggestion ( t : Ty < ' _ > , val : u128 , negative : bool ) -> Option < & ' static str > {
208
208
use syntax:: ast:: IntTy :: * ;
209
209
use syntax:: ast:: UintTy :: * ;
210
210
macro_rules! find_fit {
@@ -215,10 +215,10 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
215
215
match $ty {
216
216
$( $type => {
217
217
$( if !negative && val <= uint_ty_range( $utypes) . 1 {
218
- return Some ( format! ( "{:?}" , $utypes) )
218
+ return Some ( $utypes. name_str ( ) )
219
219
} ) *
220
220
$( if val <= int_ty_range( $itypes) . 1 as u128 + _neg {
221
- return Some ( format! ( "{:?}" , $itypes) )
221
+ return Some ( $itypes. name_str ( ) )
222
222
} ) *
223
223
None
224
224
} , ) +
@@ -281,7 +281,7 @@ fn lint_int_literal<'a, 'tcx>(
281
281
if let Node :: Expr ( par_e) = cx. tcx . hir ( ) . get ( par_id) {
282
282
if let hir:: ExprKind :: Struct ( ..) = par_e. kind {
283
283
if is_range_literal ( cx. sess ( ) , par_e)
284
- && lint_overflowing_range_endpoint ( cx, lit, v, max, e, par_e, t)
284
+ && lint_overflowing_range_endpoint ( cx, lit, v, max, e, par_e, t. name_str ( ) )
285
285
{
286
286
// The overflowing literal lint was overridden.
287
287
return ;
@@ -292,7 +292,7 @@ fn lint_int_literal<'a, 'tcx>(
292
292
cx. span_lint (
293
293
OVERFLOWING_LITERALS ,
294
294
e. span ,
295
- & format ! ( "literal out of range for `{:? }`" , t) ,
295
+ & format ! ( "literal out of range for `{}`" , t. name_str ( ) ) ,
296
296
) ;
297
297
}
298
298
}
@@ -338,6 +338,7 @@ fn lint_uint_literal<'a, 'tcx>(
338
338
}
339
339
hir:: ExprKind :: Struct ( ..)
340
340
if is_range_literal ( cx. sess ( ) , par_e) => {
341
+ let t = t. name_str ( ) ;
341
342
if lint_overflowing_range_endpoint ( cx, lit, lit_val, max, e, par_e, t) {
342
343
// The overflowing literal lint was overridden.
343
344
return ;
@@ -353,7 +354,7 @@ fn lint_uint_literal<'a, 'tcx>(
353
354
cx. span_lint (
354
355
OVERFLOWING_LITERALS ,
355
356
e. span ,
356
- & format ! ( "literal out of range for `{:? }`" , t) ,
357
+ & format ! ( "literal out of range for `{}`" , t. name_str ( ) ) ,
357
358
) ;
358
359
}
359
360
}
@@ -379,8 +380,7 @@ fn lint_literal<'a, 'tcx>(
379
380
}
380
381
ty:: Float ( t) => {
381
382
let is_infinite = match lit. node {
382
- ast:: LitKind :: Float ( v, _) |
383
- ast:: LitKind :: FloatUnsuffixed ( v) => {
383
+ ast:: LitKind :: Float ( v, _) => {
384
384
match t {
385
385
ast:: FloatTy :: F32 => v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) ,
386
386
ast:: FloatTy :: F64 => v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) ,
@@ -389,9 +389,11 @@ fn lint_literal<'a, 'tcx>(
389
389
_ => bug ! ( ) ,
390
390
} ;
391
391
if is_infinite == Ok ( true ) {
392
- cx. span_lint ( OVERFLOWING_LITERALS ,
393
- e. span ,
394
- & format ! ( "literal out of range for `{:?}`" , t) ) ;
392
+ cx. span_lint (
393
+ OVERFLOWING_LITERALS ,
394
+ e. span ,
395
+ & format ! ( "literal out of range for `{}`" , t. name_str( ) ) ,
396
+ ) ;
395
397
}
396
398
}
397
399
_ => { }
0 commit comments