@@ -13,21 +13,18 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
13
13
match stmt. kind {
14
14
StatementKind :: Assign ( box ( og_place, Rvalue :: Ref ( region, borrow_knd, place) ) ) => {
15
15
for ( idx, ( p_ref, p_elem) ) in place. iter_projections ( ) . enumerate ( ) {
16
- if p_elem == ProjectionElem :: Deref
17
- && !p_ref. projection . is_empty ( )
18
- && region. is_erased ( )
19
- {
20
- // The type that we are derefing
16
+ if p_elem == ProjectionElem :: Deref && !p_ref. projection . is_empty ( ) {
17
+ // The type that we are derefing.
21
18
let ty = p_ref. ty ( local_decl, tcx) . ty ;
22
19
let temp = patch. new_temp ( ty, stmt. source_info . span ) ;
23
20
24
21
// Because we are assigning this right before original statement
25
- // we are using index i of statement
22
+ // we are using index i of statement.
26
23
let loc = Location { block : block, statement_index : i } ;
27
24
patch. add_statement ( loc, StatementKind :: StorageLive ( temp) ) ;
28
25
29
26
// We are adding current p_ref's projections to our
30
- // temp value
27
+ // temp value.
31
28
let deref_place =
32
29
Place :: from ( p_ref. local ) . project_deeper ( p_ref. projection , tcx) ;
33
30
patch. add_assign (
@@ -37,7 +34,7 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
37
34
) ;
38
35
39
36
// We are creating a place by using our temp value's location
40
- // and copying derefed values which we need to create new statement
37
+ // and copying derefed values which we need to create new statement.
41
38
let temp_place =
42
39
Place :: from ( temp) . project_deeper ( & place. projection [ idx..] , tcx) ;
43
40
let new_stmt = Statement {
@@ -48,12 +45,17 @@ pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
48
45
) ) ) ,
49
46
} ;
50
47
51
- // Replace current statement with newly created one
48
+ // Replace current statement with newly created one.
52
49
* stmt = new_stmt;
53
50
54
51
// Since our job with the temp is done it should be gone
55
52
let loc = Location { block : block, statement_index : statement_len } ;
56
53
patch. add_statement ( loc, StatementKind :: StorageDead ( temp) ) ;
54
+
55
+ // As all projections are off the base projection, if there are
56
+ // multiple derefs in the middle of projection, it might cause
57
+ // unsoundness, to not let that happen we break the loop.
58
+ break ;
57
59
}
58
60
}
59
61
}
0 commit comments