Skip to content

Commit 44c5f7e

Browse files
Ignore fake borrows for packed field check
1 parent f44efbf commit 44c5f7e

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

compiler/rustc_middle/src/mir/visit.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,8 @@ impl PlaceContext {
13941394
pub fn is_borrow(self) -> bool {
13951395
matches!(
13961396
self,
1397-
PlaceContext::NonMutatingUse(
1398-
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow
1399-
) | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
1397+
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow)
1398+
| PlaceContext::MutatingUse(MutatingUseContext::Borrow)
14001399
)
14011400
}
14021401

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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() {}

0 commit comments

Comments
 (0)