@@ -19,11 +19,24 @@ use rustc_middle::ty::TyCtxt;
1919///
2020/// It also removes *never*-used constants, since it had all the information
2121/// needed to do that too, including updating the debug info.
22- pub ( super ) struct SingleUseConsts ;
22+ pub ( super ) enum SingleUseConsts {
23+ TempOnly ,
24+ Full ,
25+ }
2326
2427impl < ' tcx > crate :: MirPass < ' tcx > for SingleUseConsts {
28+ fn name ( & self ) -> & ' static str {
29+ match self {
30+ SingleUseConsts :: TempOnly => "SingleUseConsts-temp-only" ,
31+ SingleUseConsts :: Full => "SingleUseConsts-full" ,
32+ }
33+ }
34+
2535 fn is_enabled ( & self , sess : & rustc_session:: Session ) -> bool {
26- sess. mir_opt_level ( ) > 0
36+ match self {
37+ SingleUseConsts :: TempOnly => sess. mir_opt_level ( ) == 1 ,
38+ SingleUseConsts :: Full => sess. mir_opt_level ( ) > 1 ,
39+ }
2740 }
2841
2942 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
@@ -46,6 +59,11 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
4659 continue ;
4760 } ;
4861
62+ let local_has_debug_info = finder. locals_in_debug_info . contains ( local) ;
63+ if local_has_debug_info && matches ! ( self , SingleUseConsts :: TempOnly ) {
64+ continue ;
65+ }
66+
4967 // We're only changing an operand, not the terminator kinds or successors
5068 let basic_blocks = body. basic_blocks . as_mut_preserves_cfg ( ) ;
5169 let init_statement_kind = std:: mem:: replace (
@@ -61,7 +79,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
6179
6280 let mut replacer = LocalReplacer { tcx, local, operand : Some ( operand) } ;
6381
64- if finder . locals_in_debug_info . contains ( local ) {
82+ if local_has_debug_info {
6583 for var_debug_info in & mut body. var_debug_info {
6684 replacer. visit_var_debug_info ( var_debug_info) ;
6785 }
0 commit comments