@@ -136,6 +136,13 @@ fn lint_overflowing_range_endpoint<'tcx>(
136
136
expr : & ' tcx hir:: Expr < ' tcx > ,
137
137
ty : & str ,
138
138
) -> 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
+
139
146
// We only want to handle exclusive (`..`) ranges,
140
147
// which are represented as `ExprKind::Struct`.
141
148
let par_id = cx. tcx . hir ( ) . parent_id ( expr. hir_id ) ;
@@ -157,13 +164,19 @@ fn lint_overflowing_range_endpoint<'tcx>(
157
164
} ;
158
165
let Ok ( start) = cx. sess ( ) . source_map ( ) . span_to_snippet ( eps[ 0 ] . span ) else { return false } ;
159
166
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
+ }
166
178
} ;
179
+
167
180
cx. emit_spanned_lint (
168
181
OVERFLOWING_LITERALS ,
169
182
struct_expr. span ,
@@ -172,7 +185,7 @@ fn lint_overflowing_range_endpoint<'tcx>(
172
185
suggestion : struct_expr. span ,
173
186
start,
174
187
literal : lit_val - 1 ,
175
- suffix,
188
+ suffix : & suffix ,
176
189
} ,
177
190
) ;
178
191
0 commit comments