1
Fork 0

Rollup merge of #82789 - csmoe:issue-82772, r=estebank

Get with field index from pattern slice instead of directly indexing

Closes #82772
r? ``@estebank``

https://github.com/rust-lang/rust/pull/82789#issuecomment-796921977
> ``@estebank`` So the real cause is we only generate single pattern for Box here
615b03aeaa/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs (L1130-L1132)
But in the replacing function, it tries to index on the 1-length pattern slice with field 1, thus out of bounds.
615b03aeaa/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs (L1346)
This commit is contained in:
Yuki Okushi 2021-03-14 13:07:31 +09:00 committed by GitHub
commit 0d9a6edb50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 6 deletions

View file

@ -1343,7 +1343,9 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
match &mut fields {
Fields::Vec(pats) => {
for (i, pat) in new_pats {
pats[i] = pat
if let Some(p) = pats.get_mut(i) {
*p = pat;
}
}
}
Fields::Filtered { fields, .. } => {