You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #71217 - estebank:tail-borrow-sugg, r=pnkfelix
Suggest `;` or assignment to drop borrows in tail exprs
Address the diagnostics part of #70844.
```
error[E0597]: `counter` does not live long enough
--> $DIR/issue-54556-niconii.rs:22:20
|
LL | if let Ok(_) = counter.lock() { }
| ^^^^^^^-------
| |
| borrowed value does not live long enough
| a temporary with access to the borrow is created here ...
...
LL | }
| -
| |
| `counter` dropped here while still borrowed
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `std::result::Result<MutexGuard<'_>, ()>`
|
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
|
LL | if let Ok(_) = counter.lock() { };
| ^
```
Copy file name to clipboardExpand all lines: src/test/ui/nll/issue-54382-use-span-of-tail-of-block.stderr
+4-1
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,10 @@ LL |
13
13
LL | ;
14
14
| - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
15
15
|
16
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
16
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
Copy file name to clipboardExpand all lines: src/test/ui/nll/issue-54556-niconii.stderr
+4-1
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,10 @@ LL | }
13
13
| `counter` dropped here while still borrowed
14
14
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `std::result::Result<MutexGuard<'_>, ()>`
15
15
|
16
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
16
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
Copy file name to clipboardExpand all lines: src/test/ui/nll/issue-54556-stephaneyfx.stderr
+6-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,12 @@ LL | }
12
12
| `stmt` dropped here while still borrowed
13
13
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `std::iter::Map<Rows<'_>, [closure@$DIR/issue-54556-stephaneyfx.rs:28:14: 28:23]>`
14
14
|
15
-
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
15
+
= note: the temporary is part of an expression at the end of a block;
16
+
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
17
+
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
Copy file name to clipboardExpand all lines: src/test/ui/nll/issue-54556-temps-in-tail-diagnostic.stderr
+4-1
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,10 @@ LL |
12
12
LL | ;
13
13
| - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `D`
14
14
|
15
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
15
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
| a temporary with access to the borrow is created here ...
10
10
|
11
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
11
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
| a temporary with access to the borrow is created here ...
22
25
|
23
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
26
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
| a temporary with access to the borrow is created here ...
34
40
|
35
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
41
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
@@ -44,7 +53,10 @@ LL | let _ = { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; //
44
53
| | borrowed value does not live long enough
45
54
| a temporary with access to the borrow is created here ...
46
55
|
47
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
56
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
57
+
|
58
+
LL | let _ = { let mut _t1 = D(Box::new("t1")); D(&_t1).end(); } ; // suggest `;`
@@ -56,7 +68,10 @@ LL | let _u = { let mut _t1 = D(Box::new("t1")); D(&_t1).unit() } ; //
56
68
| | borrowed value does not live long enough
57
69
| a temporary with access to the borrow is created here ...
58
70
|
59
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
71
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
72
+
|
73
+
LL | let _u = { let mut _t1 = D(Box::new("t1")); D(&_t1).unit(); } ; // suggest `;`
@@ -68,7 +83,12 @@ LL | let _x = { let mut _t1 = D(Box::new("t1")); D(&_t1).end() } ; //
68
83
| | borrowed value does not live long enough
69
84
| a temporary with access to the borrow is created here ...
70
85
|
71
-
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
86
+
= note: the temporary is part of an expression at the end of a block;
87
+
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
88
+
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
89
+
|
90
+
LL | let _x = { let mut _t1 = D(Box::new("t1")); let x = D(&_t1).end(); x } ; // `let x = ...; x`
| a temporary with access to the borrow is created here ...
82
102
|
83
-
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
103
+
= note: the temporary is part of an expression at the end of a block;
104
+
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
105
+
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
106
+
|
107
+
LL | _y = { let mut _t1 = D(Box::new("t1")); let x = D(&_t1).end(); x } ; // `let x = ...; x`
| a temporary with access to the borrow is created here ...
95
120
|
96
-
= note: The temporary is part of an expression at the end of a block. Consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped.
121
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
| a temporary with access to the borrow is created here ...
108
136
|
109
-
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
137
+
= note: the temporary is part of an expression at the end of a block;
138
+
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
139
+
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
140
+
|
141
+
LL | fn f() -> String { let mut _t1 = D(Box::new("t1")); let x = D(&_t1).end(); x } // `let x = ...; x`
Copy file name to clipboardExpand all lines: src/test/ui/span/destructor-restrictions.stderr
+6-1
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,12 @@ LL | };
11
11
| |
12
12
| `*a` dropped here while still borrowed
13
13
|
14
-
= note: The temporary is part of an expression at the end of a block. Consider forcing this temporary to be dropped sooner, before the block's local variables are dropped. For example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block.
14
+
= note: the temporary is part of an expression at the end of a block;
15
+
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped
16
+
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block
0 commit comments