File tree 2 files changed +31
-4
lines changed
compiler/rustc_middle/src/mir
2 files changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -1364,13 +1364,13 @@ impl PlaceContext {
1364
1364
matches ! ( self , PlaceContext :: MutatingUse ( MutatingUseContext :: Drop ) )
1365
1365
}
1366
1366
1367
- /// Returns `true` if this place context represents a borrow.
1367
+ /// Returns `true` if this place context represents a borrow, excluding fake borrows
1368
+ /// (which are an artifact of borrowck and not actually borrows in runtime MIR).
1368
1369
pub fn is_borrow ( self ) -> bool {
1369
1370
matches ! (
1370
1371
self ,
1371
- PlaceContext :: NonMutatingUse (
1372
- NonMutatingUseContext :: SharedBorrow | NonMutatingUseContext :: FakeBorrow
1373
- ) | PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow )
1372
+ PlaceContext :: NonMutatingUse ( NonMutatingUseContext :: SharedBorrow )
1373
+ | PlaceContext :: MutatingUse ( MutatingUseContext :: Borrow )
1374
1374
)
1375
1375
}
1376
1376
Original file line number Diff line number Diff line change
1
+ //@ check-pass
2
+
3
+ // Regression test for <https://github.com/rust-lang/rust/issues/137250>.
4
+
5
+ // Ensure that we don't emit unaligned packed field reference errors for the fake
6
+ // borrows that we generate during match lowering. These fake borrows are there to
7
+ // ensure in *borrow-checking* that we don't modify the value being matched, but
8
+ // they are removed after the MIR is processed by `CleanupPostBorrowck`.
9
+
10
+ #[ repr( packed) ]
11
+ pub struct Packed ( i32 ) ;
12
+
13
+ fn f ( x : Packed ) {
14
+ match & x {
15
+ Packed ( 4 ) => { } ,
16
+ _ if true => { } ,
17
+ _ => { }
18
+ }
19
+
20
+ match x {
21
+ Packed ( 4 ) => { } ,
22
+ _ if true => { } ,
23
+ _ => { }
24
+ }
25
+ }
26
+
27
+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments