about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAman Arora <me@aman-arora.com>2021-07-09 03:55:03 -0400
committerAman Arora <me@aman-arora.com>2021-07-09 03:55:03 -0400
commit6195d6dcace1bc0f9b6d37089d33b8bed786c371 (patch)
tree052874c7c5b5718733195f30f436377bcb7bed3a
parentc55db232d87320d9fc3f466baeee36eb64e49e68 (diff)
downloadrust-6195d6dcace1bc0f9b6d37089d33b8bed786c371.tar.gz
rust-6195d6dcace1bc0f9b6d37089d33b8bed786c371.zip
Move optimization to the central processing function
-rw-r--r--compiler/rustc_typeck/src/check/upvar.rs9
-rw-r--r--src/test/ui/closures/2229_closure_analysis/move_closure.rs4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/move_closure.stderr4
-rw-r--r--src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs2
-rw-r--r--src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr2
5 files changed, 8 insertions, 13 deletions
diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs
index 6360eccb6f6..6a086370713 100644
--- a/compiler/rustc_typeck/src/check/upvar.rs
+++ b/compiler/rustc_typeck/src/check/upvar.rs
@@ -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 {
@@ -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);
         }
@@ -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) {
diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.rs b/src/test/ui/closures/2229_closure_analysis/move_closure.rs
index ed778e956ba..f196a9774cb 100644
--- a/src/test/ui/closures/2229_closure_analysis/move_closure.rs
+++ b/src/test/ui/closures/2229_closure_analysis/move_closure.rs
@@ -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
     };
 
@@ -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
     };
 
diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr b/src/test/ui/closures/2229_closure_analysis/move_closure.stderr
index 563ccf06e00..13c55534797 100644
--- a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/move_closure.stderr
@@ -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;
@@ -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;
diff --git a/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs b/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs
index 37a2a97d442..e7edc0bbce3 100644
--- a/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs
+++ b/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs
@@ -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
 }
diff --git a/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr b/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr
index b727c06d952..87d5d5bee07 100644
--- a/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr
+++ b/src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr
@@ -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);