@@ -136,6 +136,13 @@ fn lint_overflowing_range_endpoint<'tcx>(
136136 expr : & ' tcx hir:: Expr < ' tcx > ,
137137 ty : & str ,
138138) -> bool {
139+ let ( expr, cast_ty) = if let Node :: Expr ( par_expr) = cx. tcx . hir ( ) . get ( cx. tcx . hir ( ) . parent_id ( expr. hir_id ) )
140+ && let ExprKind :: Cast ( _, ty) = par_expr. kind {
141+ ( par_expr, Some ( ty) )
142+ } else {
143+ ( expr, None )
144+ } ;
145+
139146 // We only want to handle exclusive (`..`) ranges,
140147 // which are represented as `ExprKind::Struct`.
141148 let par_id = cx. tcx . hir ( ) . parent_id ( expr. hir_id ) ;
@@ -157,13 +164,19 @@ fn lint_overflowing_range_endpoint<'tcx>(
157164 } ;
158165 let Ok ( start) = cx. sess ( ) . source_map ( ) . span_to_snippet ( eps[ 0 ] . span ) else { return false } ;
159166
160- use rustc_ast:: { LitIntType , LitKind } ;
161- let suffix = match lit. node {
162- LitKind :: Int ( _, LitIntType :: Signed ( s) ) => s. name_str ( ) ,
163- LitKind :: Int ( _, LitIntType :: Unsigned ( s) ) => s. name_str ( ) ,
164- LitKind :: Int ( _, LitIntType :: Unsuffixed ) => "" ,
165- _ => bug ! ( ) ,
167+ let suffix = if let Some ( cast_ty) = cast_ty {
168+ let Ok ( ty) = cx. sess ( ) . source_map ( ) . span_to_snippet ( cast_ty. span ) else { return false } ;
169+ format ! ( " as {}" , ty)
170+ } else {
171+ use rustc_ast:: { LitIntType , LitKind } ;
172+ match lit. node {
173+ LitKind :: Int ( _, LitIntType :: Signed ( s) ) => s. name_str ( ) . to_owned ( ) ,
174+ LitKind :: Int ( _, LitIntType :: Unsigned ( s) ) => s. name_str ( ) . to_owned ( ) ,
175+ LitKind :: Int ( _, LitIntType :: Unsuffixed ) => "" . to_owned ( ) ,
176+ _ => bug ! ( ) ,
177+ }
166178 } ;
179+
167180 cx. emit_spanned_lint (
168181 OVERFLOWING_LITERALS ,
169182 struct_expr. span ,
@@ -172,7 +185,7 @@ fn lint_overflowing_range_endpoint<'tcx>(
172185 suggestion : struct_expr. span ,
173186 start,
174187 literal : lit_val - 1 ,
175- suffix,
188+ suffix : & suffix ,
176189 } ,
177190 ) ;
178191
0 commit comments