diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-08 09:06:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-08 09:06:33 +0100 |
| commit | 7fb36f2d3ba44636f8d5ab3bd5b0c2a359c407a9 (patch) | |
| tree | f5a7e9ac577f4f3f20d2a3b4f7f9f7fd55232e64 /compiler/rustc_pattern_analysis/src | |
| parent | bf2ba8611e433b8138c06772f845cf367d2a8b05 (diff) | |
| parent | 0825ad3fb0488cbca375d6eb8d0af4dadbed5a91 (diff) | |
| download | rust-7fb36f2d3ba44636f8d5ab3bd5b0c2a359c407a9.tar.gz rust-7fb36f2d3ba44636f8d5ab3bd5b0c2a359c407a9.zip | |
Rollup merge of #120214 - Nadrieril:fix-120210, r=pnkfelix
match lowering: consistently lower bindings deepest-first
Currently when lowering match expressions to MIR, we do a funny little dance with the order of bindings. I attempt to explain it in the third commit: we handle refutable (i.e. needing a test) patterns differently than irrefutable ones. This leads to inconsistencies, as reported in https://github.com/rust-lang/rust/issues/120210. The reason we need a dance at all is for situations like:
```rust
fn foo1(x: NonCopyStruct) {
let y @ NonCopyStruct { copy_field: z } = x;
// the above should turn into
let z = x.copy_field;
let y = x;
}
```
Here the `y ```````@```````` binding will move out of `x`, so we need to copy the field first.
I believe that the inconsistency came about when we fixed https://github.com/rust-lang/rust/issues/69971, and didn't notice that the fix didn't extend to refutable patterns. My guess then is that ordering bindings by "deepest-first, otherwise source order" is a sound choice. This PR implements that (at least I hope, match lowering is hard to follow :smiling_face_with_tear:).
Fixes https://github.com/rust-lang/rust/issues/120210
r? ```````@oli-obk``````` since you merged the original fix to https://github.com/rust-lang/rust/issues/69971
cc ```````@matthewjasper```````
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
0 files changed, 0 insertions, 0 deletions
