@@ -12,10 +12,10 @@ use rustc::mir::visit::{
1212 MutVisitor , MutatingUseContext , NonMutatingUseContext , PlaceContext , Visitor ,
1313} ;
1414use rustc:: mir:: {
15- read_only, AggregateKind , BasicBlock , BinOp , Body , BodyAndCache , CastKind , ClearCrossCrate ,
16- Constant , Local , LocalDecl , LocalKind , Location , Operand , Place , PlaceBase ,
17- ReadOnlyBodyAndCache , Rvalue , SourceInfo , SourceScope , SourceScopeData , Statement ,
18- StatementKind , Terminator , TerminatorKind , UnOp , RETURN_PLACE ,
15+ read_only, AggregateKind , BasicBlock , BinOp , Body , BodyAndCache , ClearCrossCrate , Constant ,
16+ Local , LocalDecl , LocalKind , Location , Operand , Place , PlaceBase , ReadOnlyBodyAndCache , Rvalue ,
17+ SourceInfo , SourceScope , SourceScopeData , Statement , StatementKind , Terminator , TerminatorKind ,
18+ UnOp , RETURN_PLACE ,
1919} ;
2020use rustc:: ty:: layout:: {
2121 HasDataLayout , HasTyCtxt , LayoutError , LayoutOf , Size , TargetDataLayout , TyLayout ,
@@ -29,9 +29,9 @@ use syntax::ast::Mutability;
2929
3030use crate :: const_eval:: error_to_const_error;
3131use crate :: interpret:: {
32- self , intern_const_alloc_recursive, truncate , AllocId , Allocation , Frame , ImmTy , Immediate ,
33- InterpCx , LocalState , LocalValue , Memory , MemoryKind , OpTy , Operand as InterpOperand , PlaceTy ,
34- Pointer , ScalarMaybeUndef , StackPopCleanup ,
32+ self , intern_const_alloc_recursive, AllocId , Allocation , Frame , ImmTy , Immediate , InterpCx ,
33+ LocalState , LocalValue , Memory , MemoryKind , OpTy , Operand as InterpOperand , PlaceTy , Pointer ,
34+ ScalarMaybeUndef , StackPopCleanup ,
3535} ;
3636use crate :: rustc:: ty:: subst:: Subst ;
3737use crate :: transform:: { MirPass , MirSource } ;
@@ -539,57 +539,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
539539 Some ( ( ) )
540540 }
541541
542- fn check_cast (
543- & mut self ,
544- op : & Operand < ' tcx > ,
545- ty : Ty < ' tcx > ,
546- source_info : SourceInfo ,
547- place_layout : TyLayout < ' tcx > ,
548- ) -> Option < ( ) > {
549- if !ty. is_integral ( ) || !op. ty ( & self . local_decls , self . tcx ) . is_integral ( ) {
550- return Some ( ( ) ) ;
551- }
552-
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. This can occur when casting an enum with one variant
558- // to an integer. Such enums are represented as ZSTs but still have a discriminant value
559- // which can be casted.
560- if value. layout . is_zst ( ) {
561- return Some ( ( ) ) ;
562- }
563-
564- let value_size = value. layout . size ;
565- let value_bits = value. to_scalar ( ) . and_then ( |r| r. to_bits ( value_size) ) ;
566- if let Ok ( value_bits) = value_bits {
567- let truncated = truncate ( value_bits, place_layout. size ) ;
568- if truncated != value_bits {
569- let scope = source_info. scope ;
570- let lint_root = match & self . source_scopes [ scope] . local_data {
571- ClearCrossCrate :: Set ( data) => data. lint_root ,
572- ClearCrossCrate :: Clear => return None ,
573- } ;
574- self . tcx . lint_hir (
575- :: rustc:: lint:: builtin:: CONST_ERR ,
576- lint_root,
577- source_info. span ,
578- & format ! (
579- "truncating cast: the value {} requires {} bits but the target type is \
580- only {} bits",
581- value_bits,
582- value_size. bits( ) ,
583- place_layout. size. bits( )
584- ) ,
585- ) ;
586- return None ;
587- }
588- }
589-
590- Some ( ( ) )
591- }
592-
593542 fn const_prop (
594543 & mut self ,
595544 rvalue : & Rvalue < ' tcx > ,
@@ -651,11 +600,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
651600 }
652601 }
653602
654- Rvalue :: Cast ( CastKind :: Misc , op, ty) => {
655- trace ! ( "checking Cast(Misc, {:?}, {:?})" , op, ty) ;
656- self . check_cast ( op, ty, source_info, place_layout) ?;
657- }
658-
659603 _ => { }
660604 }
661605
0 commit comments