@@ -92,7 +92,7 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
92
92
}
93
93
94
94
match DefUse :: for_place ( * place, context) {
95
- Some ( DefUse :: Def ) => {
95
+ DefUse :: Def => {
96
96
if let PlaceContext :: MutatingUse (
97
97
MutatingUseContext :: Call | MutatingUseContext :: AsmOutput ,
98
98
) = context
@@ -105,8 +105,8 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
105
105
self . 0 . kill ( place. local ) ;
106
106
}
107
107
}
108
- Some ( DefUse :: Use ) => self . 0 . gen_ ( place. local ) ,
109
- None => { }
108
+ DefUse :: Use => self . 0 . gen_ ( place. local ) ,
109
+ DefUse :: PartialWrite | DefUse :: NonUse => { }
110
110
}
111
111
112
112
self . visit_projection ( place. as_ref ( ) , context, location) ;
@@ -131,23 +131,29 @@ impl<'tcx> Visitor<'tcx> for YieldResumeEffect<'_> {
131
131
}
132
132
133
133
#[ derive( Eq , PartialEq , Clone ) ]
134
- enum DefUse {
134
+ pub enum DefUse {
135
+ /// Full write to the local.
135
136
Def ,
137
+ /// Read of any part of the local.
136
138
Use ,
139
+ /// Partial write to the local.
140
+ PartialWrite ,
141
+ /// Non-use, like debuginfo.
142
+ NonUse ,
137
143
}
138
144
139
145
impl DefUse {
140
146
fn apply ( state : & mut DenseBitSet < Local > , place : Place < ' _ > , context : PlaceContext ) {
141
147
match DefUse :: for_place ( place, context) {
142
- Some ( DefUse :: Def ) => state. kill ( place. local ) ,
143
- Some ( DefUse :: Use ) => state. gen_ ( place. local ) ,
144
- None => { }
148
+ DefUse :: Def => state. kill ( place. local ) ,
149
+ DefUse :: Use => state. gen_ ( place. local ) ,
150
+ DefUse :: PartialWrite | DefUse :: NonUse => { }
145
151
}
146
152
}
147
153
148
- fn for_place ( place : Place < ' _ > , context : PlaceContext ) -> Option < DefUse > {
154
+ pub fn for_place ( place : Place < ' _ > , context : PlaceContext ) -> DefUse {
149
155
match context {
150
- PlaceContext :: NonUse ( _) => None ,
156
+ PlaceContext :: NonUse ( _) => DefUse :: NonUse ,
151
157
152
158
PlaceContext :: MutatingUse (
153
159
MutatingUseContext :: Call
@@ -156,21 +162,20 @@ impl DefUse {
156
162
| MutatingUseContext :: Store
157
163
| MutatingUseContext :: Deinit ,
158
164
) => {
165
+ // Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a use.
159
166
if place. is_indirect ( ) {
160
- // Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a
161
- // use.
162
- Some ( DefUse :: Use )
167
+ DefUse :: Use
163
168
} else if place. projection . is_empty ( ) {
164
- Some ( DefUse :: Def )
169
+ DefUse :: Def
165
170
} else {
166
- None
171
+ DefUse :: PartialWrite
167
172
}
168
173
}
169
174
170
175
// Setting the discriminant is not a use because it does no reading, but it is also not
171
176
// a def because it does not overwrite the whole place
172
177
PlaceContext :: MutatingUse ( MutatingUseContext :: SetDiscriminant ) => {
173
- place. is_indirect ( ) . then_some ( DefUse :: Use )
178
+ if place. is_indirect ( ) { DefUse :: Use } else { DefUse :: PartialWrite }
174
179
}
175
180
176
181
// All other contexts are uses...
@@ -188,7 +193,7 @@ impl DefUse {
188
193
| NonMutatingUseContext :: PlaceMention
189
194
| NonMutatingUseContext :: FakeBorrow
190
195
| NonMutatingUseContext :: SharedBorrow ,
191
- ) => Some ( DefUse :: Use ) ,
196
+ ) => DefUse :: Use ,
192
197
193
198
PlaceContext :: MutatingUse ( MutatingUseContext :: Projection )
194
199
| PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Projection ) => {
0 commit comments