@@ -84,7 +84,7 @@ impl<'a, 'tcx> Qualif {
8484}
8585
8686/// What kind of item we are in.
87- #[ derive( Copy , Clone , PartialEq , Eq ) ]
87+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
8888enum Mode {
8989 Const ,
9090 Static ,
@@ -383,6 +383,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
383383 // Collect all the temps we need to promote.
384384 let mut promoted_temps = BitSet :: new_empty ( self . temp_promotion_state . len ( ) ) ;
385385
386+ debug ! ( "qualify_const: promotion_candidates={:?}" , self . promotion_candidates) ;
386387 for candidate in & self . promotion_candidates {
387388 match * candidate {
388389 Candidate :: Ref ( Location { block : bb, statement_index : stmt_idx } ) => {
@@ -414,6 +415,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
414415 & local: & Local ,
415416 _: PlaceContext < ' tcx > ,
416417 _: Location ) {
418+ debug ! ( "visit_local: local={:?}" , local) ;
417419 let kind = self . mir . local_kind ( local) ;
418420 match kind {
419421 LocalKind :: ReturnPointer => {
@@ -435,6 +437,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
435437 }
436438
437439 if !self . temp_promotion_state [ local] . is_promotable ( ) {
440+ debug ! ( "visit_local: (not promotable) local={:?}" , local) ;
438441 self . add ( Qualif :: NOT_PROMOTABLE ) ;
439442 }
440443
@@ -451,6 +454,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
451454 place : & Place < ' tcx > ,
452455 context : PlaceContext < ' tcx > ,
453456 location : Location ) {
457+ debug ! ( "visit_place: place={:?} context={:?} location={:?}" , place, context, location) ;
454458 match * place {
455459 Place :: Local ( ref local) => self . visit_local ( local, context, location) ,
456460 Place :: Promoted ( _) => bug ! ( "promoting already promoted MIR" ) ,
@@ -557,6 +561,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
557561 }
558562
559563 fn visit_operand ( & mut self , operand : & Operand < ' tcx > , location : Location ) {
564+ debug ! ( "visit_operand: operand={:?} location={:?}" , operand, location) ;
560565 self . super_operand ( operand, location) ;
561566
562567 match * operand {
@@ -591,6 +596,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
591596 }
592597
593598 fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
599+ debug ! ( "visit_rvalue: rvalue={:?} location={:?}" , rvalue, location) ;
594600 // Recurse through operands and places.
595601 if let Rvalue :: Ref ( region, kind, ref place) = * rvalue {
596602 let mut is_reborrow = false ;
@@ -696,6 +702,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
696702 }
697703 }
698704
705+ debug ! ( "visit_rvalue: forbidden_mut={:?}" , forbidden_mut) ;
699706 if forbidden_mut {
700707 self . add ( Qualif :: NOT_CONST ) ;
701708 } else {
@@ -709,15 +716,19 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
709716 }
710717 place = & proj. base ;
711718 }
719+ debug ! ( "visit_rvalue: place={:?}" , place) ;
712720 if let Place :: Local ( local) = * place {
713721 if self . mir . local_kind ( local) == LocalKind :: Temp {
722+ debug ! ( "visit_rvalue: local={:?}" , local) ;
714723 if let Some ( qualif) = self . local_qualif [ local] {
715724 // `forbidden_mut` is false, so we can safely ignore
716725 // `MUTABLE_INTERIOR` from the local's qualifications.
717726 // This allows borrowing fields which don't have
718727 // `MUTABLE_INTERIOR`, from a type that does, e.g.:
719728 // `let _: &'static _ = &(Cell::new(1), 2).1;`
729+ debug ! ( "visit_rvalue: qualif={:?}" , qualif) ;
720730 if ( qualif - Qualif :: MUTABLE_INTERIOR ) . is_empty ( ) {
731+ debug ! ( "visit_rvalue: candidate={:?}" , candidate) ;
721732 self . promotion_candidates . push ( candidate) ;
722733 }
723734 }
@@ -815,6 +826,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
815826 bb : BasicBlock ,
816827 kind : & TerminatorKind < ' tcx > ,
817828 location : Location ) {
829+ debug ! ( "visit_terminator_kind: bb={:?} kind={:?} location={:?}" , bb, kind, location) ;
818830 if let TerminatorKind :: Call { ref func, ref args, ref destination, .. } = * kind {
819831 self . visit_operand ( func, location) ;
820832
@@ -972,6 +984,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
972984 let candidate = Candidate :: Argument { bb, index : i } ;
973985 if is_shuffle && i == 2 {
974986 if this. qualif . is_empty ( ) {
987+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
975988 this. promotion_candidates . push ( candidate) ;
976989 } else {
977990 span_err ! ( this. tcx. sess, this. span, E0526 ,
@@ -998,6 +1011,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
9981011 // We can error out with a hard error if the argument is not
9991012 // constant here.
10001013 if ( this. qualif - Qualif :: NOT_PROMOTABLE ) . is_empty ( ) {
1014+ debug ! ( "visit_terminator_kind: candidate={:?}" , candidate) ;
10011015 this. promotion_candidates . push ( candidate) ;
10021016 } else {
10031017 this. tcx . sess . span_err ( this. span ,
@@ -1075,6 +1089,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
10751089 dest : & Place < ' tcx > ,
10761090 rvalue : & Rvalue < ' tcx > ,
10771091 location : Location ) {
1092+ debug ! ( "visit_assign: dest={:?} rvalue={:?} location={:?}" , dest, rvalue, location) ;
10781093 self . visit_rvalue ( rvalue, location) ;
10791094
10801095 // Check the allowed const fn argument forms.
@@ -1123,10 +1138,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
11231138 }
11241139
11251140 fn visit_source_info ( & mut self , source_info : & SourceInfo ) {
1141+ debug ! ( "visit_source_info: source_info={:?}" , source_info) ;
11261142 self . span = source_info. span ;
11271143 }
11281144
11291145 fn visit_statement ( & mut self , bb : BasicBlock , statement : & Statement < ' tcx > , location : Location ) {
1146+ debug ! ( "visit_statement: bb={:?} statement={:?} location={:?}" , bb, statement, location) ;
11301147 self . nest ( |this| {
11311148 this. visit_source_info ( & statement. source_info ) ;
11321149 match statement. kind {
@@ -1150,6 +1167,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
11501167 bb : BasicBlock ,
11511168 terminator : & Terminator < ' tcx > ,
11521169 location : Location ) {
1170+ debug ! ( "visit_terminator: bb={:?} terminator={:?} location={:?}" , bb, terminator, location) ;
11531171 self . nest ( |this| this. super_terminator ( bb, terminator, location) ) ;
11541172 }
11551173}
@@ -1216,6 +1234,7 @@ impl MirPass for QualifyAndPromoteConstants {
12161234 hir:: BodyOwnerKind :: Static ( hir:: MutMutable ) => Mode :: StaticMut ,
12171235 } ;
12181236
1237+ debug ! ( "run_pass: mode={:?}" , mode) ;
12191238 if mode == Mode :: Fn || mode == Mode :: ConstFn {
12201239 // This is ugly because Qualifier holds onto mir,
12211240 // which can't be mutated until its scope ends.
@@ -1258,6 +1277,7 @@ impl MirPass for QualifyAndPromoteConstants {
12581277 // In `const` and `static` everything without `StorageDead`
12591278 // is `'static`, we don't have to create promoted MIR fragments,
12601279 // just remove `Drop` and `StorageDead` on "promoted" locals.
1280+ debug ! ( "run_pass: promoted_temps={:?}" , promoted_temps) ;
12611281 for block in mir. basic_blocks_mut ( ) {
12621282 block. statements . retain ( |statement| {
12631283 match statement. kind {
0 commit comments