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
}
@@ -1936,6 +1936,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1936
1936
fn calculate_fake_borrows < ' b > (
1937
1937
& mut self ,
1938
1938
fake_borrows : & ' b FxIndexSet < Place < ' tcx > > ,
1939
+ scrutinee_base : PlaceBase ,
1939
1940
temp_span : Span ,
1940
1941
) -> Vec < ( Place < ' tcx > , Local ) > {
1941
1942
let tcx = self . tcx ;
@@ -1946,6 +1947,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1946
1947
1947
1948
// Insert a Shallow borrow of the prefixes of any fake borrows.
1948
1949
for place in fake_borrows {
1950
+ if let PlaceBase :: Local ( l) = scrutinee_base
1951
+ && l != place. local
1952
+ {
1953
+ // The base of this place is a temporary created for deref patterns. We don't emit
1954
+ // fake borrows for these as they are not initialized in all branches.
1955
+ // FIXME(deref_patterns): is this sound?
1956
+ continue ;
1957
+ }
1958
+
1949
1959
let mut cursor = place. projection . as_ref ( ) ;
1950
1960
while let [ proj_base @ .., elem] = cursor {
1951
1961
cursor = proj_base;
0 commit comments