@@ -484,7 +484,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
484
484
lint : & ' static lint:: Lint ,
485
485
source_info : SourceInfo ,
486
486
message : & ' static str ,
487
- panic : AssertKind < ConstInt > ,
487
+ panic : AssertKind < impl std :: fmt :: Debug > ,
488
488
) -> Option < ( ) > {
489
489
let lint_root = self . lint_root ( source_info) ?;
490
490
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> {
1004
1004
let expected = ScalarMaybeUninit :: from ( Scalar :: from_bool ( * expected) ) ;
1005
1005
let value_const = self . ecx . read_scalar ( value) . unwrap ( ) ;
1006
1006
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
+ }
1007
1019
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
+ }
1012
1028
} ;
1013
1029
let msg = match msg {
1014
1030
AssertKind :: DivisionByZero ( op) => {
0 commit comments