1
Fork 0

Perform OpaqueCast field projection on HIR, too.

This is necessary for closure captures in 2021 edition, as they capture individual fields, not the full mentioned variables. So it may try to capture a field of an opaque (because the hidden type is known to be something with a field).
This commit is contained in:
Oli Scherer 2023-07-24 14:47:32 +00:00
parent d14569bd64
commit e390dc9c36
8 changed files with 30 additions and 0 deletions

View file

@ -236,6 +236,9 @@ fn strip_prefix<'a, 'tcx>(
}
assert_matches!(iter.next(), Some(ProjectionElem::Field(..)));
}
HirProjectionKind::OpaqueCast => {
assert_matches!(iter.next(), Some(ProjectionElem::OpaqueCast(..)));
}
HirProjectionKind::Index | HirProjectionKind::Subslice => {
bug!("unexpected projection kind: {:?}", projection);
}

View file

@ -1074,6 +1074,9 @@ impl<'tcx> Cx<'tcx> {
variant_index,
name: field,
},
HirProjectionKind::OpaqueCast => {
ExprKind::Use { source: self.thir.exprs.push(captured_place_expr) }
}
HirProjectionKind::Index | HirProjectionKind::Subslice => {
// We don't capture these projections, so we can ignore them here
continue;