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
Auto merge of rust-lang#88214 - notriddle:notriddle/for-loop-span-drop-temps-mut, r=nagisa
rustc: use more correct span data in for loop desugaring
Fixesrust-lang#82462
Before:
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
|
LL | for x in DroppingSlice(&*v).iter(); {
| +
After:
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
|
LL | };
| +
This seems like a reasonable fix: since the desugared "expr_drop_temps_mut" contains the entire desugared loop construct, its span should contain the entire loop construct as well.
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
2
+
--> $DIR/issue-82462.rs:18:9
3
+
|
4
+
LL | for x in DroppingSlice(&*v).iter() {
5
+
| ------------------
6
+
| | |
7
+
| | immutable borrow occurs here
8
+
| a temporary with access to the immutable borrow is created here ...
9
+
LL | v.push(*x);
10
+
| ^ mutable borrow occurs here
11
+
LL | break;
12
+
LL | }
13
+
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice`
14
+
|
15
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
16
+
|
17
+
LL | };
18
+
| +
19
+
20
+
error: aborting due to previous error
21
+
22
+
For more information about this error, try `rustc --explain E0502`.
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable
2
+
--> $DIR/issue-82462.rs:18:9
3
+
|
4
+
LL | for x in DroppingSlice(&*v).iter() {
5
+
| ------------------
6
+
| | |
7
+
| | immutable borrow occurs here
8
+
| a temporary with access to the immutable borrow is created here ...
9
+
LL | v.push(*x);
10
+
| ^^^^^^^^^^ mutable borrow occurs here
11
+
LL | break;
12
+
LL | }
13
+
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice`
14
+
|
15
+
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped
16
+
|
17
+
LL | };
18
+
| +
19
+
20
+
error: aborting due to previous error
21
+
22
+
For more information about this error, try `rustc --explain E0502`.
0 commit comments