File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -180,14 +180,19 @@ impl Local {
180180 field_indices,
181181 ..
182182 } => {
183+ let field_projections = place
184+ . projections
185+ . iter ( )
186+ . filter ( |proj| matches ! ( proj. kind, ProjectionKind :: Field ( _, _) ) )
187+ . collect :: < Vec < _ > > ( ) ;
183188 is_potentially_local_place ( * local_id, place)
184189 // If there were projections other than field projections, err on the side of caution and say that they
185190 // _might_ be mutating something.
186191 //
187192 // The reason we use `<=` and not `==` is that a mutation of `struct` or `struct.field1` should count as
188193 // mutation of the child fields such as `struct.field1.field2`
189- && place . projections . len ( ) <= field_indices. len ( )
190- && iter:: zip ( & place . projections , field_indices. iter ( ) . copied ( ) . rev ( ) ) . all ( |( proj, field_idx) | {
194+ && field_projections . len ( ) <= field_indices. len ( )
195+ && iter:: zip ( & field_projections , field_indices. iter ( ) . copied ( ) . rev ( ) ) . all ( |( proj, field_idx) | {
191196 match proj. kind {
192197 ProjectionKind :: Field ( f_idx, _) => f_idx == field_idx,
193198 // If this is a projection we don't expect, it _might_ be mutating something
Original file line number Diff line number Diff line change @@ -472,3 +472,22 @@ fn issue15321() {
472472 //~^ unnecessary_unwrap
473473 }
474474}
475+
476+ mod issue16188 {
477+ struct Foo {
478+ value : Option < i32 > ,
479+ }
480+
481+ impl Foo {
482+ pub fn bar ( & mut self ) {
483+ let print_value = |v : i32 | {
484+ println ! ( "{}" , v) ;
485+ } ;
486+
487+ if self . value . is_none ( ) {
488+ self . value = Some ( 10 ) ;
489+ print_value ( self . value . unwrap ( ) ) ;
490+ }
491+ }
492+ }
493+ }
You can’t perform that action at this time.
0 commit comments