8
8
use rustc_hir:: def_id:: LocalDefId ;
9
9
use rustc_index:: bit_set:: DenseBitSet ;
10
10
use rustc_middle:: mir:: visit:: { NonMutatingUseContext , PlaceContext , Visitor } ;
11
- use rustc_middle:: mir:: { Body , Location , Operand , Place , RETURN_PLACE , Terminator , TerminatorKind } ;
11
+ use rustc_middle:: mir:: {
12
+ Body , Local , Location , Operand , Place , RETURN_PLACE , Terminator , TerminatorKind ,
13
+ } ;
12
14
use rustc_middle:: ty:: { self , DeducedParamAttrs , Ty , TyCtxt } ;
13
15
use rustc_session:: config:: OptLevel ;
14
16
use tracing:: instrument;
@@ -31,18 +33,23 @@ impl DeduceReadOnly {
31
33
read_only_when_freeze : DenseBitSet :: new_filled ( arg_count) ,
32
34
}
33
35
}
36
+
37
+ fn arg_index ( & self , local : Local ) -> Option < usize > {
38
+ if local == RETURN_PLACE || local. index ( ) > self . read_only . domain_size ( ) {
39
+ None
40
+ } else {
41
+ Some ( local. index ( ) - 1 )
42
+ }
43
+ }
34
44
}
35
45
36
46
impl < ' tcx > Visitor < ' tcx > for DeduceReadOnly {
37
47
fn visit_place ( & mut self , place : & Place < ' tcx > , context : PlaceContext , _location : Location ) {
38
- // We're only interested in arguments.
39
- if place. local == RETURN_PLACE || place. local . index ( ) > self . read_only . domain_size ( ) {
40
- return ;
41
- }
42
- let arg_index = place. local . index ( ) - 1 ;
43
48
if place. is_indirect ( ) {
44
49
return ;
45
50
}
51
+ // We're only interested in arguments.
52
+ let Some ( arg_index) = self . arg_index ( place. local ) else { return } ;
46
53
match context {
47
54
PlaceContext :: MutatingUse ( ..) => {
48
55
// This is a mutation, so mark it as such.
@@ -87,16 +94,13 @@ impl<'tcx> Visitor<'tcx> for DeduceReadOnly {
87
94
if let TerminatorKind :: Call { ref args, .. } = terminator. kind {
88
95
for arg in args {
89
96
if let Operand :: Move ( place) = arg. node {
90
- let local = place. local ;
91
- if place. is_indirect ( )
92
- || local == RETURN_PLACE
93
- || local. index ( ) > self . read_only . domain_size ( )
94
- {
97
+ if place. is_indirect ( ) {
95
98
continue ;
96
99
}
97
- let arg_index = local. index ( ) - 1 ;
98
- self . read_only . remove ( arg_index) ;
99
- self . read_only_when_freeze . remove ( arg_index) ;
100
+ if let Some ( arg_index) = self . arg_index ( place. local ) {
101
+ self . read_only . remove ( arg_index) ;
102
+ self . read_only_when_freeze . remove ( arg_index) ;
103
+ }
100
104
}
101
105
}
102
106
} ;
0 commit comments