From 6195d6dcace1bc0f9b6d37089d33b8bed786c371 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Fri, 9 Jul 2021 03:55:03 -0400 Subject: [PATCH] Move optimization to the central processing function --- compiler/rustc_typeck/src/check/upvar.rs | 9 ++------- .../ui/closures/2229_closure_analysis/move_closure.rs | 4 ++-- .../closures/2229_closure_analysis/move_closure.stderr | 4 ++-- .../2229_closure_analysis/optimization/edge_case.rs | 2 +- .../2229_closure_analysis/optimization/edge_case.stderr | 2 +- 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 6360eccb6f6f..6a086370713b 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 ed778e956ba4..f196a9774cb8 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 563ccf06e006..13c55534797f 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 37a2a97d4427..e7edc0bbce39 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 //~| 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 b727c06d9528..87d5d5bee07d 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);