@@ -546,38 +546,42 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
546
546
source_info : SourceInfo ,
547
547
place_layout : TyLayout < ' tcx > ,
548
548
) -> Option < ( ) > {
549
- if ty. is_integral ( ) && op. ty ( & self . local_decls , self . tcx ) . is_integral ( ) {
550
- let value = self . use_ecx ( source_info, |this| {
551
- this. ecx . read_immediate ( this. ecx . eval_operand ( op, None ) ?)
552
- } ) ?;
549
+ if !ty. is_integral ( ) || !op. ty ( & self . local_decls , self . tcx ) . is_integral ( ) {
550
+ return Some ( ( ) ) ;
551
+ }
553
552
554
- // Do not try to read bits for ZSTs
555
- if !value. layout . is_zst ( ) {
556
- let value_size = value. layout . size ;
557
- let value_bits = value. to_scalar ( ) . and_then ( |r| r. to_bits ( value_size) ) ;
558
- if let Ok ( value_bits) = value_bits {
559
- let truncated = truncate ( value_bits, place_layout. size ) ;
560
- if truncated != value_bits {
561
- let scope = source_info. scope ;
562
- let lint_root = match & self . source_scopes [ scope] . local_data {
563
- ClearCrossCrate :: Set ( data) => data. lint_root ,
564
- ClearCrossCrate :: Clear => return None ,
565
- } ;
566
- self . tcx . lint_hir (
567
- :: rustc:: lint:: builtin:: CONST_ERR ,
568
- lint_root,
569
- source_info. span ,
570
- & format ! (
571
- "truncating cast: the value {} requires {} bits but \
572
- the target type is only {} bits",
573
- value_bits,
574
- value_size. bits( ) ,
575
- place_layout. size. bits( )
576
- ) ,
577
- ) ;
578
- return None ;
579
- }
580
- }
553
+ let value = self . use_ecx ( source_info, |this| {
554
+ this. ecx . read_immediate ( this. ecx . eval_operand ( op, None ) ?)
555
+ } ) ?;
556
+
557
+ // Do not try to read bits for ZSTs
558
+ if value. layout . is_zst ( ) {
559
+ return Some ( ( ) ) ;
560
+ }
561
+
562
+ let value_size = value. layout . size ;
563
+ let value_bits = value. to_scalar ( ) . and_then ( |r| r. to_bits ( value_size) ) ;
564
+ if let Ok ( value_bits) = value_bits {
565
+ let truncated = truncate ( value_bits, place_layout. size ) ;
566
+ if truncated != value_bits {
567
+ let scope = source_info. scope ;
568
+ let lint_root = match & self . source_scopes [ scope] . local_data {
569
+ ClearCrossCrate :: Set ( data) => data. lint_root ,
570
+ ClearCrossCrate :: Clear => return None ,
571
+ } ;
572
+ self . tcx . lint_hir (
573
+ :: rustc:: lint:: builtin:: CONST_ERR ,
574
+ lint_root,
575
+ source_info. span ,
576
+ & format ! (
577
+ "truncating cast: the value {} requires {} bits but the target type is \
578
+ only {} bits",
579
+ value_bits,
580
+ value_size. bits( ) ,
581
+ place_layout. size. bits( )
582
+ ) ,
583
+ ) ;
584
+ return None ;
581
585
}
582
586
}
583
587
0 commit comments