1
Fork 0

Only borrow place for matching under specific conditions

This commit is contained in:
Roxane 2021-02-23 23:39:33 -05:00
parent 685a4c6b6b
commit 74fc64303f
11 changed files with 193 additions and 49 deletions

View file

@ -100,7 +100,7 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
// single and multiple variants.
// For single variants, enums are not captured completely.
// We keep track of VariantIdx so we can use this information
// if the next ProjectionElem is a Field
// if the next ProjectionElem is a Field.
variant = Some(*idx);
continue;
}

View file

@ -420,6 +420,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
| ExprKind::PlaceTypeAscription { .. }
| ExprKind::ValueTypeAscription { .. } => {
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
let place = unpack!(block = this.as_place(block, expr));
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
this.cfg.push_assign(block, source_info, destination, rvalue);
@ -436,6 +437,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
let place = unpack!(block = this.as_place(block, expr));
let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
this.cfg.push_assign(block, source_info, destination, rvalue);

View file

@ -68,7 +68,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let match_pairs = mem::take(&mut candidate.match_pairs);
if let [MatchPair { pattern: Pat { kind: box PatKind::Or { pats }, .. }, place }] =
&*match_pairs.clone()
&*match_pairs
{
existing_bindings.extend_from_slice(&new_bindings);
mem::swap(&mut candidate.bindings, &mut existing_bindings);
@ -155,12 +155,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
ascription: thir::pattern::Ascription { variance, user_ty, user_ty_span },
} => {
// Apply the type ascription to the value at `match_pair.place`, which is the
// value being matched, taking the variance field into account.
let place = match_pair.place.clone().into_place(self.tcx, self.typeck_results);
candidate.ascriptions.push(Ascription {
span: user_ty_span,
user_ty,
source: place,
source: match_pair.place.clone().into_place(self.tcx, self.typeck_results),
variance,
});
@ -175,12 +173,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
PatKind::Binding { name, mutability, mode, var, ty, ref subpattern, is_primary: _ } => {
let place = match_pair.place.clone().into_place(self.tcx, self.typeck_results);
candidate.bindings.push(Binding {
name,
mutability,
span: match_pair.pattern.span,
source: place,
source: match_pair.place.clone().into_place(self.tcx, self.typeck_results),
var_id: var,
var_ty: ty,
binding_mode: mode,

View file

@ -455,32 +455,18 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
);
let fake_reads = match self.typeck_results().closure_fake_reads.get(&def_id) {
Some(vals) => {
Some(
vals.iter()
.map(|(place, cause)| {
(
self.arena.alloc(
self.convert_captured_hir_place(expr, place.clone()),
),
*cause,
)
// let var_hir_id = match val.base {
// HirPlaceBase::Upvar(upvar_id) => {
// debug!("upvar");
// upvar_id.var_path.hir_id
// }
// _ => {
// bug!(
// "Do not know how to get HirId out of Rvalue and StaticItem"
// );
// }
// };
// self.fake_read_capture_upvar(expr, val.clone(), var_hir_id)
})
.collect(),
)
}
Some(vals) => Some(
vals.iter()
.map(|(place, cause)| {
(
self.arena.alloc(
self.convert_captured_hir_place(expr, place.clone()),
),
*cause,
)
})
.collect(),
),
None => None,
};
@ -1058,6 +1044,11 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
let temp_lifetime = self.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id);
let var_ty = place.base_ty;
// The result of capture analysis in `rustc_typeck/check/upvar.rs`represents a captured path
// as it's seen for use within the closure and not at the time of closure creation.
//
// That is we see expect to see it start from a captured upvar and not something that is local
// to the closure's parent.
let var_hir_id = match place.base {
HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
base => bug!("Expected an upvar, found {:?}", base),