@@ -20,7 +20,7 @@ use rustc_target::abi::{Abi, FieldIdx, HasDataLayout, Size, TargetDataLayout, Va
2020use crate :: const_prop:: CanConstProp ;
2121use crate :: const_prop:: ConstPropMachine ;
2222use crate :: const_prop:: ConstPropMode ;
23- use crate :: errors:: AssertLint ;
23+ use crate :: errors:: { AssertLint , AssertLintKind } ;
2424use crate :: MirLint ;
2525
2626pub struct ConstPropLint ;
@@ -300,9 +300,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
300300 }
301301 }
302302
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) ;
304310 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+ ) ;
306318 }
307319 }
308320
@@ -316,13 +328,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
316328 // `AssertKind` only has an `OverflowNeg` variant, so make sure that is
317329 // appropriate to use.
318330 assert_eq ! ( op, UnOp :: Neg , "Neg is the only UnOp that can overflow" ) ;
319- let source_info = self . body . source_info ( location) ;
320331 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 ( ) ) ,
326335 ) ;
327336 return None ;
328337 }
@@ -354,7 +363,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
354363 let r_bits = r. to_scalar ( ) . to_bits ( right_size) . ok ( ) ;
355364 if r_bits. is_some_and ( |b| b >= left_size. bits ( ) as u128 ) {
356365 debug ! ( "check_binary_op: reporting assert for {:?}" , location) ;
357- let source_info = self . body . source_info ( location) ;
358366 let panic = AssertKind :: Overflow (
359367 op,
360368 match l {
@@ -368,10 +376,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
368376 } ,
369377 r. to_const_int ( ) ,
370378 ) ;
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) ;
375380 return None ;
376381 }
377382 }
@@ -382,13 +387,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
382387 let ( _res, overflow) = this. ecx . overflowing_binary_op ( op, & l, & r) ?;
383388 Ok ( overflow)
384389 } ) ? {
385- let source_info = self . body . source_info ( location) ;
386390 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 ( ) ) ,
392394 ) ;
393395 return None ;
394396 }
@@ -529,11 +531,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
529531 // Need proper const propagator for these.
530532 _ => return None ,
531533 } ;
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) ;
537535 }
538536
539537 None
0 commit comments