Skip to content

Commit 66777ad

Browse files
fix: drop eager if let scrutinee borrow during capture analysis
1 parent 7be157a commit 66777ad

5 files changed

Lines changed: 17 additions & 29 deletions

File tree

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
451451
}
452452

453453
hir::ExprKind::Let(hir::LetExpr { pat, init, .. }) => {
454-
self.walk_local(init, pat, None, || self.borrow_expr(init, BorrowKind::Immutable))?;
454+
self.walk_local(init, pat, None, || Ok(()))?;
455455
}
456456

457457
hir::ExprKind::Match(discr, arms, _) => {

tests/ui/closures/2229_closure_analysis/capture-enums.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ fn multi_variant_enum() {
2020
//~| ERROR Min Capture analysis includes:
2121
if let Info::Point(_, _, str) = point {
2222
//~^ NOTE: Capturing point[] -> Immutable
23-
//~| NOTE: Capturing point[] -> Immutable
2423
//~| NOTE: Capturing point[(2, 0)] -> ByValue
2524
//~| NOTE: Min Capture point[] -> ByValue
2625
println!("{}", str);
2726
}
2827

2928
if let Info::Meta(_, v) = meta {
3029
//~^ NOTE: Capturing meta[] -> Immutable
31-
//~| NOTE: Capturing meta[] -> Immutable
3230
//~| NOTE: Capturing meta[(1, 1)] -> ByValue
3331
//~| NOTE: Min Capture meta[] -> ByValue
3432
println!("{:?}", v);

tests/ui/closures/2229_closure_analysis/capture-enums.stderr

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,18 @@ note: Capturing point[] -> Immutable
1414
|
1515
LL | if let Info::Point(_, _, str) = point {
1616
| ^^^^^
17-
note: Capturing point[] -> Immutable
18-
--> $DIR/capture-enums.rs:21:41
19-
|
20-
LL | if let Info::Point(_, _, str) = point {
21-
| ^^^^^
2217
note: Capturing point[(2, 0)] -> ByValue
2318
--> $DIR/capture-enums.rs:21:41
2419
|
2520
LL | if let Info::Point(_, _, str) = point {
2621
| ^^^^^
2722
note: Capturing meta[] -> Immutable
28-
--> $DIR/capture-enums.rs:29:35
29-
|
30-
LL | if let Info::Meta(_, v) = meta {
31-
| ^^^^
32-
note: Capturing meta[] -> Immutable
33-
--> $DIR/capture-enums.rs:29:35
23+
--> $DIR/capture-enums.rs:28:35
3424
|
3525
LL | if let Info::Meta(_, v) = meta {
3626
| ^^^^
3727
note: Capturing meta[(1, 1)] -> ByValue
38-
--> $DIR/capture-enums.rs:29:35
28+
--> $DIR/capture-enums.rs:28:35
3929
|
4030
LL | if let Info::Meta(_, v) = meta {
4131
| ^^^^
@@ -57,13 +47,13 @@ note: Min Capture point[] -> ByValue
5747
LL | if let Info::Point(_, _, str) = point {
5848
| ^^^^^
5949
note: Min Capture meta[] -> ByValue
60-
--> $DIR/capture-enums.rs:29:35
50+
--> $DIR/capture-enums.rs:28:35
6151
|
6252
LL | if let Info::Meta(_, v) = meta {
6353
| ^^^^
6454

6555
error: First Pass analysis includes:
66-
--> $DIR/capture-enums.rs:49:5
56+
--> $DIR/capture-enums.rs:47:5
6757
|
6858
LL | / || {
6959
LL | |
@@ -75,13 +65,13 @@ LL | | };
7565
| |_____^
7666
|
7767
note: Capturing point[(2, 0)] -> ByValue
78-
--> $DIR/capture-enums.rs:52:47
68+
--> $DIR/capture-enums.rs:50:47
7969
|
8070
LL | let SingleVariant::Point(_, _, str) = point;
8171
| ^^^^^
8272

8373
error: Min Capture analysis includes:
84-
--> $DIR/capture-enums.rs:49:5
74+
--> $DIR/capture-enums.rs:47:5
8575
|
8676
LL | / || {
8777
LL | |
@@ -93,7 +83,7 @@ LL | | };
9383
| |_____^
9484
|
9585
note: Min Capture point[(2, 0)] -> ByValue
96-
--> $DIR/capture-enums.rs:52:47
86+
--> $DIR/capture-enums.rs:50:47
9787
|
9888
LL | let SingleVariant::Point(_, _, str) = point;
9989
| ^^^^^

tests/ui/closures/2229_closure_analysis/if-let-patterns-capture-analysis.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ fn if_let_closure() {
1616
//~^ ERROR First Pass analysis includes:
1717
//~| ERROR Min Capture analysis includes:
1818
if let SingleVariant::Pair(ref n, s) = variant {
19-
//~^ NOTE: Capturing variant[] -> Immutable
20-
//~| NOTE: Capturing variant[(0, 0)] -> Immutable
19+
//~^ NOTE: Capturing variant[(0, 0)] -> Immutable
2120
//~| NOTE: Capturing variant[(1, 0)] -> ByValue
22-
//~| NOTE: Min Capture variant[] -> ByValue
21+
//~| NOTE: Min Capture variant[(0, 0)] -> Immutable
22+
//~| NOTE: Min Capture variant[(1, 0)] -> ByValue
2323
let _ = (n, s);
2424
}
2525
};

tests/ui/closures/2229_closure_analysis/if-let-patterns-capture-analysis.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ LL | | if let SingleVariant::Pair(ref n, s) = variant {
99
LL | | };
1010
| |_____^
1111
|
12-
note: Capturing variant[] -> Immutable
13-
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
14-
|
15-
LL | if let SingleVariant::Pair(ref n, s) = variant {
16-
| ^^^^^^^
1712
note: Capturing variant[(0, 0)] -> Immutable
1813
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
1914
|
@@ -36,7 +31,12 @@ LL | | if let SingleVariant::Pair(ref n, s) = variant {
3631
LL | | };
3732
| |_____^
3833
|
39-
note: Min Capture variant[] -> ByValue
34+
note: Min Capture variant[(0, 0)] -> Immutable
35+
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
36+
|
37+
LL | if let SingleVariant::Pair(ref n, s) = variant {
38+
| ^^^^^^^
39+
note: Min Capture variant[(1, 0)] -> ByValue
4040
--> $DIR/if-let-patterns-capture-analysis.rs:18:48
4141
|
4242
LL | if let SingleVariant::Pair(ref n, s) = variant {

0 commit comments

Comments
 (0)