@@ -1656,35 +1656,7 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
1656
1656
Mode :: Const => tcx. mir_const_qualif ( def_id) . 1 ,
1657
1657
_ => Checker :: new ( tcx, def_id, body, mode) . check_const ( ) . 1 ,
1658
1658
} ;
1659
-
1660
- // In `const` and `static` everything without `StorageDead`
1661
- // is `'static`, we don't have to create promoted MIR fragments,
1662
- // just remove `Drop` and `StorageDead` on "promoted" locals.
1663
- debug ! ( "run_pass: promoted_temps={:?}" , promoted_temps) ;
1664
- for block in body. basic_blocks_mut ( ) {
1665
- block. statements . retain ( |statement| {
1666
- match statement. kind {
1667
- StatementKind :: StorageDead ( index) => {
1668
- !promoted_temps. contains ( index)
1669
- }
1670
- _ => true
1671
- }
1672
- } ) ;
1673
- let terminator = block. terminator_mut ( ) ;
1674
- match terminator. kind {
1675
- TerminatorKind :: Drop {
1676
- location : Place {
1677
- base : PlaceBase :: Local ( index) ,
1678
- projection : None ,
1679
- } ,
1680
- target,
1681
- ..
1682
- } if promoted_temps. contains ( index) => {
1683
- terminator. kind = TerminatorKind :: Goto { target } ;
1684
- }
1685
- _ => { }
1686
- }
1687
- }
1659
+ remove_drop_and_storage_dead_on_promoted_locals ( body, promoted_temps) ;
1688
1660
}
1689
1661
1690
1662
if let Mode :: Static = mode {
@@ -1738,6 +1710,39 @@ fn check_short_circuiting_in_const_local(tcx: TyCtxt<'_>, body: &mut Body<'tcx>,
1738
1710
}
1739
1711
}
1740
1712
1713
+ /// In `const` and `static` everything without `StorageDead`
1714
+ /// is `'static`, we don't have to create promoted MIR fragments,
1715
+ /// just remove `Drop` and `StorageDead` on "promoted" locals.
1716
+ fn remove_drop_and_storage_dead_on_promoted_locals (
1717
+ body : & mut Body < ' tcx > ,
1718
+ promoted_temps : & BitSet < Local > ,
1719
+ ) {
1720
+ debug ! ( "run_pass: promoted_temps={:?}" , promoted_temps) ;
1721
+
1722
+ for block in body. basic_blocks_mut ( ) {
1723
+ block. statements . retain ( |statement| {
1724
+ match statement. kind {
1725
+ StatementKind :: StorageDead ( index) => !promoted_temps. contains ( index) ,
1726
+ _ => true
1727
+ }
1728
+ } ) ;
1729
+ let terminator = block. terminator_mut ( ) ;
1730
+ match terminator. kind {
1731
+ TerminatorKind :: Drop {
1732
+ location : Place {
1733
+ base : PlaceBase :: Local ( index) ,
1734
+ projection : None ,
1735
+ } ,
1736
+ target,
1737
+ ..
1738
+ } if promoted_temps. contains ( index) => {
1739
+ terminator. kind = TerminatorKind :: Goto { target } ;
1740
+ }
1741
+ _ => { }
1742
+ }
1743
+ }
1744
+ }
1745
+
1741
1746
fn check_non_thread_local_static_is_sync (
1742
1747
tcx : TyCtxt < ' tcx > ,
1743
1748
body : & mut Body < ' tcx > ,
0 commit comments