@@ -68,7 +68,7 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
6868 max : u128 ,
6969 expr : & ' tcx hir:: Expr ,
7070 parent_expr : & ' tcx hir:: Expr ,
71- ty : impl std :: fmt :: Debug ,
71+ ty : & str ,
7272) -> bool {
7373 // We only want to handle exclusive (`..`) ranges,
7474 // which are represented as `ExprKind::Struct`.
@@ -83,15 +83,15 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
8383 let mut err = cx. struct_span_lint (
8484 OVERFLOWING_LITERALS ,
8585 parent_expr. span ,
86- & format ! ( "range endpoint is out of range for `{:? }`" , ty) ,
86+ & format ! ( "range endpoint is out of range for `{}`" , ty) ,
8787 ) ;
8888 if let Ok ( start) = cx. sess ( ) . source_map ( ) . span_to_snippet ( eps[ 0 ] . span ) {
8989 use ast:: { LitKind , LitIntType } ;
9090 // We need to preserve the literal's suffix,
9191 // as it may determine typing information.
9292 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 ( ) ) ,
9595 LitKind :: Int ( _, LitIntType :: Unsuffixed ) => "" . to_owned ( ) ,
9696 _ => bug ! ( ) ,
9797 } ;
@@ -161,11 +161,11 @@ fn report_bin_hex_error(
161161 let ( t, actually) = match ty {
162162 attr:: IntType :: SignedInt ( t) => {
163163 let actually = sign_extend ( val, size) as i128 ;
164- ( format ! ( "{:?}" , t ) , actually. to_string ( ) )
164+ ( t . name_str ( ) , actually. to_string ( ) )
165165 }
166166 attr:: IntType :: UnsignedInt ( t) => {
167167 let actually = truncate ( val, size) ;
168- ( format ! ( "{:?}" , t ) , actually. to_string ( ) )
168+ ( t . name_str ( ) , actually. to_string ( ) )
169169 }
170170 } ;
171171 let mut err = cx. struct_span_lint (
@@ -204,7 +204,7 @@ fn report_bin_hex_error(
204204// - `uX` => `uY`
205205//
206206// 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 > {
208208 use syntax:: ast:: IntTy :: * ;
209209 use syntax:: ast:: UintTy :: * ;
210210 macro_rules! find_fit {
@@ -215,10 +215,10 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
215215 match $ty {
216216 $( $type => {
217217 $( if !negative && val <= uint_ty_range( $utypes) . 1 {
218- return Some ( format! ( "{:?}" , $utypes) )
218+ return Some ( $utypes. name_str ( ) )
219219 } ) *
220220 $( if val <= int_ty_range( $itypes) . 1 as u128 + _neg {
221- return Some ( format! ( "{:?}" , $itypes) )
221+ return Some ( $itypes. name_str ( ) )
222222 } ) *
223223 None
224224 } , ) +
@@ -281,7 +281,7 @@ fn lint_int_literal<'a, 'tcx>(
281281 if let Node :: Expr ( par_e) = cx. tcx . hir ( ) . get ( par_id) {
282282 if let hir:: ExprKind :: Struct ( ..) = par_e. kind {
283283 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 ( ) )
285285 {
286286 // The overflowing literal lint was overridden.
287287 return ;
@@ -292,7 +292,7 @@ fn lint_int_literal<'a, 'tcx>(
292292 cx. span_lint (
293293 OVERFLOWING_LITERALS ,
294294 e. span ,
295- & format ! ( "literal out of range for `{:? }`" , t) ,
295+ & format ! ( "literal out of range for `{}`" , t. name_str ( ) ) ,
296296 ) ;
297297 }
298298}
@@ -338,6 +338,7 @@ fn lint_uint_literal<'a, 'tcx>(
338338 }
339339 hir:: ExprKind :: Struct ( ..)
340340 if is_range_literal ( cx. sess ( ) , par_e) => {
341+ let t = t. name_str ( ) ;
341342 if lint_overflowing_range_endpoint ( cx, lit, lit_val, max, e, par_e, t) {
342343 // The overflowing literal lint was overridden.
343344 return ;
@@ -353,7 +354,7 @@ fn lint_uint_literal<'a, 'tcx>(
353354 cx. span_lint (
354355 OVERFLOWING_LITERALS ,
355356 e. span ,
356- & format ! ( "literal out of range for `{:? }`" , t) ,
357+ & format ! ( "literal out of range for `{}`" , t. name_str ( ) ) ,
357358 ) ;
358359 }
359360}
@@ -379,8 +380,7 @@ fn lint_literal<'a, 'tcx>(
379380 }
380381 ty:: Float ( t) => {
381382 let is_infinite = match lit. node {
382- ast:: LitKind :: Float ( v, _) |
383- ast:: LitKind :: FloatUnsuffixed ( v) => {
383+ ast:: LitKind :: Float ( v, _) => {
384384 match t {
385385 ast:: FloatTy :: F32 => v. as_str ( ) . parse ( ) . map ( f32:: is_infinite) ,
386386 ast:: FloatTy :: F64 => v. as_str ( ) . parse ( ) . map ( f64:: is_infinite) ,
@@ -389,9 +389,11 @@ fn lint_literal<'a, 'tcx>(
389389 _ => bug ! ( ) ,
390390 } ;
391391 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+ ) ;
395397 }
396398 }
397399 _ => { }
0 commit comments