@@ -10,15 +10,15 @@ use rustc_const_eval::interpret::{
1010 ImmTy , InterpCx , InterpResult , Projectable , Scalar , format_interp_error, interp_ok,
1111} ;
1212use rustc_data_structures:: fx:: FxHashSet ;
13- use rustc_hir:: HirId ;
1413use rustc_hir:: def:: DefKind ;
14+ use rustc_hir:: { HirId , find_attr} ;
1515use rustc_index:: IndexVec ;
1616use rustc_index:: bit_set:: DenseBitSet ;
1717use rustc_middle:: bug;
1818use rustc_middle:: mir:: visit:: { MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor } ;
1919use rustc_middle:: mir:: * ;
2020use rustc_middle:: ty:: layout:: { LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
21- use rustc_middle:: ty:: { self , ConstInt , ScalarInt , Ty , TyCtxt , TypeVisitableExt } ;
21+ use rustc_middle:: ty:: { self , ConstInt , GenericArgKind , ScalarInt , Ty , TyCtxt , TypeVisitableExt } ;
2222use rustc_span:: Span ;
2323use tracing:: { debug, instrument, trace} ;
2424
@@ -765,6 +765,22 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
765765 }
766766 // We failed to evaluate the discriminant, fallback to visiting all successors.
767767 }
768+ TerminatorKind :: Call { func, args : _, .. } => {
769+ if let Some ( ( def_id, generic_args) ) = func. const_fn_def ( ) {
770+ for arg in generic_args {
771+ if let GenericArgKind :: Const ( ct) = arg. kind ( )
772+ && find_attr ! ( self . tcx, def_id, RustcPanicsWhenNIsZero )
773+ && let Some ( 0 ) = ct. try_to_target_usize ( self . tcx )
774+ {
775+ self . report_assert_as_lint (
776+ location,
777+ AssertLintKind :: UnconditionalPanic ,
778+ AssertKind :: < ( ) > :: ConstNIsZero ,
779+ ) ;
780+ }
781+ }
782+ }
783+ }
768784 // None of these have Operands to const-propagate.
769785 TerminatorKind :: Goto { .. }
770786 | TerminatorKind :: UnwindResume
@@ -777,7 +793,6 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
777793 | TerminatorKind :: CoroutineDrop
778794 | TerminatorKind :: FalseEdge { .. }
779795 | TerminatorKind :: FalseUnwind { .. }
780- | TerminatorKind :: Call { .. }
781796 | TerminatorKind :: InlineAsm { .. } => { }
782797 }
783798
0 commit comments