@@ -17,7 +17,7 @@ use rustc_middle::mir::*;
17
17
use rustc_middle:: ty:: layout:: { LayoutError , LayoutOf , LayoutOfHelpers , TyAndLayout } ;
18
18
use rustc_middle:: ty:: InternalSubsts ;
19
19
use rustc_middle:: ty:: { self , ConstKind , Instance , ParamEnv , Ty , TyCtxt , TypeVisitableExt } ;
20
- use rustc_span:: { def_id:: DefId , Span } ;
20
+ use rustc_span:: { def_id:: DefId , Span , DUMMY_SP } ;
21
21
use rustc_target:: abi:: { self , Align , HasDataLayout , Size , TargetDataLayout } ;
22
22
use rustc_target:: spec:: abi:: Abi as CallAbi ;
23
23
use rustc_trait_selection:: traits;
@@ -328,9 +328,6 @@ struct ConstPropagator<'mir, 'tcx> {
328
328
tcx : TyCtxt < ' tcx > ,
329
329
param_env : ParamEnv < ' tcx > ,
330
330
local_decls : & ' mir IndexVec < Local , LocalDecl < ' tcx > > ,
331
- // Because we have `MutVisitor` we can't obtain the `SourceInfo` from a `Location`. So we store
332
- // the last known `SourceInfo` here and just keep revisiting it.
333
- source_info : Option < SourceInfo > ,
334
331
}
335
332
336
333
impl < ' tcx > LayoutOfHelpers < ' tcx > for ConstPropagator < ' _ , ' tcx > {
@@ -411,13 +408,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
411
408
)
412
409
. expect ( "failed to push initial stack frame" ) ;
413
410
414
- ConstPropagator {
415
- ecx,
416
- tcx,
417
- param_env,
418
- local_decls : & dummy_body. local_decls ,
419
- source_info : None ,
420
- }
411
+ ConstPropagator { ecx, tcx, param_env, local_decls : & dummy_body. local_decls }
421
412
}
422
413
423
414
fn get_const ( & self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
@@ -495,7 +486,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
495
486
* operand = self . operand_from_scalar (
496
487
scalar,
497
488
value. layout . ty ,
498
- self . source_info . unwrap ( ) . span ,
489
+ DUMMY_SP ,
499
490
) ;
500
491
}
501
492
}
@@ -629,12 +620,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
629
620
} ) )
630
621
}
631
622
632
- fn replace_with_const (
633
- & mut self ,
634
- rval : & mut Rvalue < ' tcx > ,
635
- value : & OpTy < ' tcx > ,
636
- source_info : SourceInfo ,
637
- ) {
623
+ fn replace_with_const ( & mut self , rval : & mut Rvalue < ' tcx > , value : & OpTy < ' tcx > ) {
638
624
if let Rvalue :: Use ( Operand :: Constant ( c) ) = rval {
639
625
match c. literal {
640
626
ConstantKind :: Ty ( c) if matches ! ( c. kind( ) , ConstKind :: Unevaluated ( ..) ) => { }
@@ -664,11 +650,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
664
650
if let Some ( Right ( imm) ) = imm {
665
651
match * imm {
666
652
interpret:: Immediate :: Scalar ( scalar) => {
667
- * rval = Rvalue :: Use ( self . operand_from_scalar (
668
- scalar,
669
- value. layout . ty ,
670
- source_info. span ,
671
- ) ) ;
653
+ * rval =
654
+ Rvalue :: Use ( self . operand_from_scalar ( scalar, value. layout . ty , DUMMY_SP ) ) ;
672
655
}
673
656
Immediate :: ScalarPair ( ..) => {
674
657
// Found a value represented as a pair. For now only do const-prop if the type
@@ -701,7 +684,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
701
684
let const_val = ConstValue :: ByRef { alloc, offset : Size :: ZERO } ;
702
685
let literal = ConstantKind :: Val ( const_val, ty) ;
703
686
* rval = Rvalue :: Use ( Operand :: Constant ( Box :: new ( Constant {
704
- span : source_info . span ,
687
+ span : DUMMY_SP ,
705
688
user_ty : None ,
706
689
literal,
707
690
} ) ) ) ;
@@ -894,8 +877,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
894
877
895
878
fn visit_statement ( & mut self , statement : & mut Statement < ' tcx > , location : Location ) {
896
879
trace ! ( "visit_statement: {:?}" , statement) ;
897
- let source_info = statement. source_info ;
898
- self . source_info = Some ( source_info) ;
899
880
match statement. kind {
900
881
StatementKind :: Assign ( box ( place, ref mut rval) ) => {
901
882
let can_const_prop = self . ecx . machine . can_const_prop [ place. local ] ;
@@ -905,7 +886,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
905
886
// consists solely of uninitialized memory (so it doesn't capture any locals).
906
887
if let Some ( ref value) = self . get_const ( place) && self . should_const_prop ( value) {
907
888
trace ! ( "replacing {:?} with {:?}" , rval, value) ;
908
- self . replace_with_const ( rval, value, source_info ) ;
889
+ self . replace_with_const ( rval, value) ;
909
890
if can_const_prop == ConstPropMode :: FullConstProp
910
891
|| can_const_prop == ConstPropMode :: OnlyInsideOwnBlock
911
892
{
@@ -977,8 +958,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
977
958
}
978
959
979
960
fn visit_terminator ( & mut self , terminator : & mut Terminator < ' tcx > , location : Location ) {
980
- let source_info = terminator. source_info ;
981
- self . source_info = Some ( source_info) ;
982
961
self . super_terminator ( terminator, location) ;
983
962
984
963
match & mut terminator. kind {
@@ -991,7 +970,7 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
991
970
* cond = self . operand_from_scalar (
992
971
value_const,
993
972
self . tcx . types . bool ,
994
- source_info . span ,
973
+ DUMMY_SP ,
995
974
) ;
996
975
}
997
976
}
0 commit comments