@@ -92,7 +92,7 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
9292 }
9393
9494 match DefUse :: for_place ( * place, context) {
95- Some ( DefUse :: Def ) => {
95+ DefUse :: Def => {
9696 if let PlaceContext :: MutatingUse (
9797 MutatingUseContext :: Call | MutatingUseContext :: AsmOutput ,
9898 ) = context
@@ -105,8 +105,8 @@ impl<'tcx> Visitor<'tcx> for TransferFunction<'_> {
105105 self . 0 . kill ( place. local ) ;
106106 }
107107 }
108- Some ( DefUse :: Use ) => self . 0 . gen_ ( place. local ) ,
109- None => { }
108+ DefUse :: Use => self . 0 . gen_ ( place. local ) ,
109+ DefUse :: PartialWrite | DefUse :: NonUse => { }
110110 }
111111
112112 self . visit_projection ( place. as_ref ( ) , context, location) ;
@@ -131,23 +131,29 @@ impl<'tcx> Visitor<'tcx> for YieldResumeEffect<'_> {
131131}
132132
133133#[ derive( Eq , PartialEq , Clone ) ]
134- enum DefUse {
134+ pub enum DefUse {
135+ /// Full write to the local.
135136 Def ,
137+ /// Read of any part of the local.
136138 Use ,
139+ /// Partial write to the local.
140+ PartialWrite ,
141+ /// Non-use, like debuginfo.
142+ NonUse ,
137143}
138144
139145impl DefUse {
140146 fn apply ( state : & mut DenseBitSet < Local > , place : Place < ' _ > , context : PlaceContext ) {
141147 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 => { }
145151 }
146152 }
147153
148- fn for_place ( place : Place < ' _ > , context : PlaceContext ) -> Option < DefUse > {
154+ pub fn for_place ( place : Place < ' _ > , context : PlaceContext ) -> DefUse {
149155 match context {
150- PlaceContext :: NonUse ( _) => None ,
156+ PlaceContext :: NonUse ( _) => DefUse :: NonUse ,
151157
152158 PlaceContext :: MutatingUse (
153159 MutatingUseContext :: Call
@@ -156,21 +162,20 @@ impl DefUse {
156162 | MutatingUseContext :: Store
157163 | MutatingUseContext :: Deinit ,
158164 ) => {
165+ // Treat derefs as a use of the base local. `*p = 4` is not a def of `p` but a use.
159166 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
163168 } else if place. projection . is_empty ( ) {
164- Some ( DefUse :: Def )
169+ DefUse :: Def
165170 } else {
166- None
171+ DefUse :: PartialWrite
167172 }
168173 }
169174
170175 // Setting the discriminant is not a use because it does no reading, but it is also not
171176 // a def because it does not overwrite the whole place
172177 PlaceContext :: MutatingUse ( MutatingUseContext :: SetDiscriminant ) => {
173- place. is_indirect ( ) . then_some ( DefUse :: Use )
178+ if place. is_indirect ( ) { DefUse :: Use } else { DefUse :: PartialWrite }
174179 }
175180
176181 // All other contexts are uses...
@@ -188,7 +193,7 @@ impl DefUse {
188193 | NonMutatingUseContext :: PlaceMention
189194 | NonMutatingUseContext :: FakeBorrow
190195 | NonMutatingUseContext :: SharedBorrow ,
191- ) => Some ( DefUse :: Use ) ,
196+ ) => DefUse :: Use ,
192197
193198 PlaceContext :: MutatingUse ( MutatingUseContext :: Projection )
194199 | PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: Projection ) => {
0 commit comments