@@ -20,7 +20,7 @@ use rustc_target::abi::{Abi, FieldIdx, HasDataLayout, Size, TargetDataLayout, Va
20
20
use crate :: const_prop:: CanConstProp ;
21
21
use crate :: const_prop:: ConstPropMachine ;
22
22
use crate :: const_prop:: ConstPropMode ;
23
- use crate :: errors:: AssertLint ;
23
+ use crate :: errors:: { AssertLint , AssertLintKind } ;
24
24
use crate :: MirLint ;
25
25
26
26
pub struct ConstPropLint ;
@@ -300,9 +300,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
300
300
}
301
301
}
302
302
303
- fn report_assert_as_lint ( & self , source_info : & SourceInfo , lint : AssertLint < impl Debug > ) {
303
+ fn report_assert_as_lint (
304
+ & self ,
305
+ location : Location ,
306
+ lint_kind : AssertLintKind ,
307
+ assert_kind : AssertKind < impl Debug > ,
308
+ ) {
309
+ let source_info = self . body . source_info ( location) ;
304
310
if let Some ( lint_root) = self . lint_root ( * source_info) {
305
- self . tcx . emit_spanned_lint ( lint. lint ( ) , lint_root, source_info. span , lint) ;
311
+ let span = source_info. span ;
312
+ self . tcx . emit_spanned_lint (
313
+ lint_kind. lint ( ) ,
314
+ lint_root,
315
+ span,
316
+ AssertLint { span, assert_kind, lint_kind } ,
317
+ ) ;
306
318
}
307
319
}
308
320
@@ -316,13 +328,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
316
328
// `AssertKind` only has an `OverflowNeg` variant, so make sure that is
317
329
// appropriate to use.
318
330
assert_eq ! ( op, UnOp :: Neg , "Neg is the only UnOp that can overflow" ) ;
319
- let source_info = self . body . source_info ( location) ;
320
331
self . report_assert_as_lint (
321
- source_info,
322
- AssertLint :: ArithmeticOverflow (
323
- source_info. span ,
324
- AssertKind :: OverflowNeg ( val. to_const_int ( ) ) ,
325
- ) ,
332
+ location,
333
+ AssertLintKind :: ArithmeticOverflow ,
334
+ AssertKind :: OverflowNeg ( val. to_const_int ( ) ) ,
326
335
) ;
327
336
return None ;
328
337
}
@@ -354,7 +363,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
354
363
let r_bits = r. to_scalar ( ) . to_bits ( right_size) . ok ( ) ;
355
364
if r_bits. is_some_and ( |b| b >= left_size. bits ( ) as u128 ) {
356
365
debug ! ( "check_binary_op: reporting assert for {:?}" , location) ;
357
- let source_info = self . body . source_info ( location) ;
358
366
let panic = AssertKind :: Overflow (
359
367
op,
360
368
match l {
@@ -368,10 +376,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
368
376
} ,
369
377
r. to_const_int ( ) ,
370
378
) ;
371
- self . report_assert_as_lint (
372
- source_info,
373
- AssertLint :: ArithmeticOverflow ( source_info. span , panic) ,
374
- ) ;
379
+ self . report_assert_as_lint ( location, AssertLintKind :: ArithmeticOverflow , panic) ;
375
380
return None ;
376
381
}
377
382
}
@@ -382,13 +387,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
382
387
let ( _res, overflow) = this. ecx . overflowing_binary_op ( op, & l, & r) ?;
383
388
Ok ( overflow)
384
389
} ) ? {
385
- let source_info = self . body . source_info ( location) ;
386
390
self . report_assert_as_lint (
387
- source_info,
388
- AssertLint :: ArithmeticOverflow (
389
- source_info. span ,
390
- AssertKind :: Overflow ( op, l. to_const_int ( ) , r. to_const_int ( ) ) ,
391
- ) ,
391
+ location,
392
+ AssertLintKind :: ArithmeticOverflow ,
393
+ AssertKind :: Overflow ( op, l. to_const_int ( ) , r. to_const_int ( ) ) ,
392
394
) ;
393
395
return None ;
394
396
}
@@ -529,11 +531,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
529
531
// Need proper const propagator for these.
530
532
_ => return None ,
531
533
} ;
532
- let source_info = self . body . source_info ( location) ;
533
- self . report_assert_as_lint (
534
- source_info,
535
- AssertLint :: UnconditionalPanic ( source_info. span , msg) ,
536
- ) ;
534
+ self . report_assert_as_lint ( location, AssertLintKind :: UnconditionalPanic , msg) ;
537
535
}
538
536
539
537
None
0 commit comments