@@ -19,11 +19,24 @@ use rustc_middle::ty::TyCtxt;
19
19
///
20
20
/// It also removes *never*-used constants, since it had all the information
21
21
/// 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
+ }
23
26
24
27
impl < ' 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
+
25
35
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
+ }
27
40
}
28
41
29
42
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
@@ -46,6 +59,11 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
46
59
continue ;
47
60
} ;
48
61
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
+
49
67
// We're only changing an operand, not the terminator kinds or successors
50
68
let basic_blocks = body. basic_blocks . as_mut_preserves_cfg ( ) ;
51
69
let init_statement_kind = std:: mem:: replace (
@@ -61,7 +79,7 @@ impl<'tcx> crate::MirPass<'tcx> for SingleUseConsts {
61
79
62
80
let mut replacer = LocalReplacer { tcx, local, operand : Some ( operand) } ;
63
81
64
- if finder . locals_in_debug_info . contains ( local ) {
82
+ if local_has_debug_info {
65
83
for var_debug_info in & mut body. var_debug_info {
66
84
replacer. visit_var_debug_info ( var_debug_info) ;
67
85
}
0 commit comments