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 } ;
@@ -361,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
361
361
}
362
362
363
363
if let Some ( ref borrows) = fake_borrows {
364
- self . calculate_fake_borrows ( borrows, scrutinee_span)
364
+ self . calculate_fake_borrows ( borrows, scrutinee_place_builder . base ( ) , scrutinee_span)
365
365
} else {
366
366
Vec :: new ( )
367
367
}
@@ -1862,6 +1862,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1862
1862
fn calculate_fake_borrows < ' b > (
1863
1863
& mut self ,
1864
1864
fake_borrows : & ' b FxIndexSet < Place < ' tcx > > ,
1865
+ scrutinee_base : PlaceBase ,
1865
1866
temp_span : Span ,
1866
1867
) -> Vec < ( Place < ' tcx > , Local ) > {
1867
1868
let tcx = self . tcx ;
@@ -1872,6 +1873,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1872
1873
1873
1874
// Insert a Shallow borrow of the prefixes of any fake borrows.
1874
1875
for place in fake_borrows {
1876
+ if let PlaceBase :: Local ( l) = scrutinee_base
1877
+ && l != place. local
1878
+ {
1879
+ // The base of this place is a temporary created for deref patterns. We don't emit
1880
+ // fake borrows for these as they are not initialized in all branches.
1881
+ // FIXME(deref_patterns): does this allow for subtle bugs?
1882
+ continue ;
1883
+ }
1884
+
1875
1885
let mut cursor = place. projection . as_ref ( ) ;
1876
1886
while let [ proj_base @ .., elem] = cursor {
1877
1887
cursor = proj_base;
0 commit comments