diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2025-02-22 01:01:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-22 01:01:41 +0100 |
| commit | fa62fbe4b804a7d814d6e9629e0275a4e1d3843f (patch) | |
| tree | 99c79d75b1ba584886e5847155dd2cf9d06a6543 /compiler/rustc_middle/src | |
| parent | 890c4d2e2663b9f50ebc1128ae5a89ad1febe6cb (diff) | |
| parent | 0713bbcdfa91c02d35c13482ef506906b4035990 (diff) | |
| download | rust-fa62fbe4b804a7d814d6e9629e0275a4e1d3843f.tar.gz rust-fa62fbe4b804a7d814d6e9629e0275a4e1d3843f.zip | |
Rollup merge of #137257 - compiler-errors:fake-borrow-of-packed-field, r=oli-obk
Ignore fake borrows for packed field check We should not emit unaligned packed field reference errors for the fake borrows that we generate during match lowering. These fake borrows are there to ensure in *borrow-checking* that we don't modify the value being matched (which is why this only occurs when there's a match guard, in this case `if true`), but they are removed after the MIR is processed by `CleanupPostBorrowck`, since they're really just there to cause borrowck errors if necessary. I modified `PlaceContext::is_borrow` since that's used by the packed field check: https://github.com/rust-lang/rust/blob/17c1c329a5512d718b67ef6797538b154016cd34/compiler/rustc_mir_transform/src/check_packed_ref.rs#L40 It's only used in one other place, in the SROA optimization (by which fake borrows are removed, so it doesn't matter): https://github.com/rust-lang/rust/blob/17c1c329a5512d718b67ef6797538b154016cd34/compiler/rustc_mir_dataflow/src/value_analysis.rs#L922 Fixes https://github.com/rust-lang/rust/issues/137250
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/mir/visit.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 98e8f269c57..af09a6d570b 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1364,13 +1364,13 @@ impl PlaceContext { matches!(self, PlaceContext::MutatingUse(MutatingUseContext::Drop)) } - /// Returns `true` if this place context represents a borrow. + /// Returns `true` if this place context represents a borrow, excluding fake borrows + /// (which are an artifact of borrowck and not actually borrows in runtime MIR). pub fn is_borrow(self) -> bool { matches!( self, - PlaceContext::NonMutatingUse( - NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow - ) | PlaceContext::MutatingUse(MutatingUseContext::Borrow) + PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) + | PlaceContext::MutatingUse(MutatingUseContext::Borrow) ) } |
