1
Fork 0

Auto merge of #118316 - Mark-Simulacrum:delete-copy-to-upvars, r=cjgillot

Remove borrowck Upvar duplication

This cuts out an extra allocation and copying over from the already cached closure capture information.
This commit is contained in:
bors 2023-11-26 21:47:19 +00:00
commit 6cf088810f
10 changed files with 35 additions and 50 deletions

View file

@ -66,7 +66,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
));
let imm_borrow_derefed = self.upvars[upvar_index.index()]
.place
.place
.deref_tys()
.any(|ty| matches!(ty.kind(), ty::Ref(.., hir::Mutability::Not)));
@ -85,7 +84,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
if self.is_upvar_field_projection(access_place.as_ref()).is_some() {
reason = ", as it is not declared as mutable".to_string();
} else {
let name = self.upvars[upvar_index.index()].place.to_string(self.infcx.tcx);
let name = self.upvars[upvar_index.index()].to_string(self.infcx.tcx);
reason = format!(", as `{name}` is not declared as mutable");
}
}
@ -388,7 +387,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Place::ty_from(local, proj_base, self.body, self.infcx.tcx).ty
));
let captured_place = &self.upvars[upvar_index.index()].place;
let captured_place = self.upvars[upvar_index.index()];
err.span_label(span, format!("cannot {act}"));