@@ -484,7 +484,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
484484 lint : & ' static lint:: Lint ,
485485 source_info : SourceInfo ,
486486 message : & ' static str ,
487- panic : AssertKind < ConstInt > ,
487+ panic : AssertKind < impl std :: fmt :: Debug > ,
488488 ) -> Option < ( ) > {
489489 let lint_root = self . lint_root ( source_info) ?;
490490 self . tcx . struct_span_lint_hir ( lint, lint_root, source_info. span , |lint| {
@@ -1004,11 +1004,27 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10041004 let expected = ScalarMaybeUninit :: from ( Scalar :: from_bool ( * expected) ) ;
10051005 let value_const = self . ecx . read_scalar ( value) . unwrap ( ) ;
10061006 if expected != value_const {
1007+ enum DbgVal < T > {
1008+ Val ( T ) ,
1009+ Underscore ,
1010+ }
1011+ impl < T : std:: fmt:: Debug > std:: fmt:: Debug for DbgVal < T > {
1012+ fn fmt ( & self , fmt : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1013+ match self {
1014+ Self :: Val ( val) => val. fmt ( fmt) ,
1015+ Self :: Underscore => fmt. write_str ( "_" ) ,
1016+ }
1017+ }
1018+ }
10071019 let mut eval_to_int = |op| {
1008- let op = self
1009- . eval_operand ( op, source_info)
1010- . expect ( "if we got here, it must be const" ) ;
1011- self . ecx . read_immediate ( op) . unwrap ( ) . to_const_int ( )
1020+ // This can be `None` if the lhs wasn't const propagated and we just
1021+ // triggered the assert on the value of the rhs.
1022+ match self . eval_operand ( op, source_info) {
1023+ Some ( op) => {
1024+ DbgVal :: Val ( self . ecx . read_immediate ( op) . unwrap ( ) . to_const_int ( ) )
1025+ }
1026+ None => DbgVal :: Underscore ,
1027+ }
10121028 } ;
10131029 let msg = match msg {
10141030 AssertKind :: DivisionByZero ( op) => {
0 commit comments