Skip to content

Commit

Permalink
Move optimization to the central processing function
Browse files Browse the repository at this point in the history
  • Loading branch information
arora-aman committed Jul 9, 2021
1 parent c55db23 commit 6195d6d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
9 changes: 2 additions & 7 deletions compiler/rustc_typeck/src/check/upvar.rs
Expand Up @@ -335,6 +335,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Apply rules for safety before inferring closure kind
let place = restrict_capture_precision(place);

let place = truncate_capture_for_optimization(&place);

let usage_span = if let Some(usage_expr) = capture_info.path_expr_id {
self.tcx.hir().span(usage_expr)
} else {
Expand Down Expand Up @@ -1638,11 +1640,6 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
place_with_id, diag_expr_id, mode
);

let place_with_id = PlaceWithHirId {
place: truncate_capture_for_optimization(&place_with_id.place),
..*place_with_id
};

if !self.capture_information.contains_key(&place_with_id.place) {
self.init_capture_info_for_place(&place_with_id, diag_expr_id);
}
Expand Down Expand Up @@ -1670,8 +1667,6 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
&place_with_id.place,
);

let place = truncate_capture_for_optimization(&place);

let place_with_id = PlaceWithHirId { place, ..*place_with_id };

if !self.capture_information.contains_key(&place_with_id.place) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/closures/2229_closure_analysis/move_closure.rs
Expand Up @@ -78,7 +78,7 @@ fn struct_contains_ref_to_another_struct_2() {
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
let _t = t.0.0;
//~^ NOTE: Capturing t[(0, 0),Deref] -> ImmBorrow
//~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
//~| NOTE: Min Capture t[(0, 0),Deref] -> ImmBorrow
};

Expand All @@ -100,7 +100,7 @@ fn struct_contains_ref_to_another_struct_3() {
//~^ ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
let _t = t.0.0;
//~^ NOTE: Capturing t[(0, 0),Deref] -> ByValue
//~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ByValue
//~| NOTE: Min Capture t[(0, 0)] -> ByValue
};

Expand Down
Expand Up @@ -190,7 +190,7 @@ LL | |
LL | | };
| |_____^
|
note: Capturing t[(0, 0),Deref] -> ImmBorrow
note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
--> $DIR/move_closure.rs:80:18
|
LL | let _t = t.0.0;
Expand Down Expand Up @@ -226,7 +226,7 @@ LL | |
LL | | };
| |_____^
|
note: Capturing t[(0, 0),Deref] -> ByValue
note: Capturing t[(0, 0),Deref,(0, 0)] -> ByValue
--> $DIR/move_closure.rs:102:18
|
LL | let _t = t.0.0;
Expand Down
Expand Up @@ -22,7 +22,7 @@ fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static {
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
//~| ERROR: First Pass analysis includes:
//~| ERROR: Min Capture analysis includes:
//~| NOTE: Capturing m[Deref,(0, 0),Deref] -> ImmBorrow
//~| NOTE: Capturing m[Deref,(0, 0),Deref,(0, 0)] -> ImmBorrow
//~| NOTE: Min Capture m[Deref,(0, 0),Deref] -> ImmBorrow
c
}
Expand Down
Expand Up @@ -13,7 +13,7 @@ error: First Pass analysis includes:
LL | let c = #[rustc_capture_analysis] || drop(&m.a.0);
| ^^^^^^^^^^^^^^^
|
note: Capturing m[Deref,(0, 0),Deref] -> ImmBorrow
note: Capturing m[Deref,(0, 0),Deref,(0, 0)] -> ImmBorrow
--> $DIR/edge_case.rs:20:48
|
LL | let c = #[rustc_capture_analysis] || drop(&m.a.0);
Expand Down

0 comments on commit 6195d6d

Please sign in to comment.