Skip to content

Commit 6195d6d

Browse files
committed
Move optimization to the central processing function
1 parent c55db23 commit 6195d6d

File tree

5 files changed

+8
-13
lines changed

5 files changed

+8
-13
lines changed

compiler/rustc_typeck/src/check/upvar.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
335335
// Apply rules for safety before inferring closure kind
336336
let place = restrict_capture_precision(place);
337337

338+
let place = truncate_capture_for_optimization(&place);
339+
338340
let usage_span = if let Some(usage_expr) = capture_info.path_expr_id {
339341
self.tcx.hir().span(usage_expr)
340342
} else {
@@ -1638,11 +1640,6 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
16381640
place_with_id, diag_expr_id, mode
16391641
);
16401642

1641-
let place_with_id = PlaceWithHirId {
1642-
place: truncate_capture_for_optimization(&place_with_id.place),
1643-
..*place_with_id
1644-
};
1645-
16461643
if !self.capture_information.contains_key(&place_with_id.place) {
16471644
self.init_capture_info_for_place(&place_with_id, diag_expr_id);
16481645
}
@@ -1670,8 +1667,6 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> {
16701667
&place_with_id.place,
16711668
);
16721669

1673-
let place = truncate_capture_for_optimization(&place);
1674-
16751670
let place_with_id = PlaceWithHirId { place, ..*place_with_id };
16761671

16771672
if !self.capture_information.contains_key(&place_with_id.place) {

src/test/ui/closures/2229_closure_analysis/move_closure.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn struct_contains_ref_to_another_struct_2() {
7878
//~^ ERROR: First Pass analysis includes:
7979
//~| ERROR: Min Capture analysis includes:
8080
let _t = t.0.0;
81-
//~^ NOTE: Capturing t[(0, 0),Deref] -> ImmBorrow
81+
//~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
8282
//~| NOTE: Min Capture t[(0, 0),Deref] -> ImmBorrow
8383
};
8484

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

src/test/ui/closures/2229_closure_analysis/move_closure.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ LL | |
190190
LL | | };
191191
| |_____^
192192
|
193-
note: Capturing t[(0, 0),Deref] -> ImmBorrow
193+
note: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
194194
--> $DIR/move_closure.rs:80:18
195195
|
196196
LL | let _t = t.0.0;
@@ -226,7 +226,7 @@ LL | |
226226
LL | | };
227227
| |_____^
228228
|
229-
note: Capturing t[(0, 0),Deref] -> ByValue
229+
note: Capturing t[(0, 0),Deref,(0, 0)] -> ByValue
230230
--> $DIR/move_closure.rs:102:18
231231
|
232232
LL | let _t = t.0.0;

src/test/ui/closures/2229_closure_analysis/optimization/edge_case.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static {
2222
//~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
2323
//~| ERROR: First Pass analysis includes:
2424
//~| ERROR: Min Capture analysis includes:
25-
//~| NOTE: Capturing m[Deref,(0, 0),Deref] -> ImmBorrow
25+
//~| NOTE: Capturing m[Deref,(0, 0),Deref,(0, 0)] -> ImmBorrow
2626
//~| NOTE: Min Capture m[Deref,(0, 0),Deref] -> ImmBorrow
2727
c
2828
}

src/test/ui/closures/2229_closure_analysis/optimization/edge_case.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ error: First Pass analysis includes:
1313
LL | let c = #[rustc_capture_analysis] || drop(&m.a.0);
1414
| ^^^^^^^^^^^^^^^
1515
|
16-
note: Capturing m[Deref,(0, 0),Deref] -> ImmBorrow
16+
note: Capturing m[Deref,(0, 0),Deref,(0, 0)] -> ImmBorrow
1717
--> $DIR/edge_case.rs:20:48
1818
|
1919
LL | let c = #[rustc_capture_analysis] || drop(&m.a.0);

0 commit comments

Comments
 (0)