5
5
//! This also includes code for pattern bindings in `let` statements and
6
6
//! function parameters.
7
7
8
- use crate :: build:: expr:: as_place:: PlaceBuilder ;
8
+ use crate :: build:: expr:: as_place:: { PlaceBase , PlaceBuilder } ;
9
9
use crate :: build:: scope:: DropKind ;
10
10
use crate :: build:: ForGuard :: { self , OutsideGuard , RefWithinGuard } ;
11
11
use crate :: build:: { BlockAnd , BlockAndExtension , Builder } ;
@@ -438,7 +438,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
438
438
}
439
439
440
440
if let Some ( ref borrows) = fake_borrows {
441
- self . calculate_fake_borrows ( borrows, scrutinee_span)
441
+ self . calculate_fake_borrows ( borrows, scrutinee_place_builder . base ( ) , scrutinee_span)
442
442
} else {
443
443
Vec :: new ( )
444
444
}
@@ -1941,6 +1941,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1941
1941
fn calculate_fake_borrows < ' b > (
1942
1942
& mut self ,
1943
1943
fake_borrows : & ' b FxIndexSet < Place < ' tcx > > ,
1944
+ scrutinee_base : PlaceBase ,
1944
1945
temp_span : Span ,
1945
1946
) -> Vec < ( Place < ' tcx > , Local ) > {
1946
1947
let tcx = self . tcx ;
@@ -1951,6 +1952,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1951
1952
1952
1953
// Insert a Shallow borrow of the prefixes of any fake borrows.
1953
1954
for place in fake_borrows {
1955
+ if let PlaceBase :: Local ( l) = scrutinee_base
1956
+ && l != place. local
1957
+ {
1958
+ // The base of this place is a temporary created for deref patterns. We don't emit
1959
+ // fake borrows for these as they are not initialized in all branches.
1960
+ // FIXME(deref_patterns): is this sound?
1961
+ continue ;
1962
+ }
1963
+
1954
1964
let mut cursor = place. projection . as_ref ( ) ;
1955
1965
while let [ proj_base @ .., elem] = cursor {
1956
1966
cursor = proj_base;
0 commit comments