forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#88214 - notriddle:notriddle/for-loop-span-dro…
…p-temps-mut, r=nagisa rustc: use more correct span data in for loop desugaring Fixes rust-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.
- Loading branch information
Showing
9 changed files
with
82 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable | ||
--> $DIR/issue-82462.rs:18:9 | ||
| | ||
LL | for x in DroppingSlice(&*v).iter() { | ||
| ------------------ | ||
| | | | ||
| | immutable borrow occurs here | ||
| a temporary with access to the immutable borrow is created here ... | ||
LL | v.push(*x); | ||
| ^ mutable borrow occurs here | ||
LL | break; | ||
LL | } | ||
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice` | ||
| | ||
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | ||
| | ||
LL | }; | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0502`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
struct DroppingSlice<'a>(&'a [i32]); | ||
|
||
impl Drop for DroppingSlice<'_> { | ||
fn drop(&mut self) { | ||
println!("hi from slice"); | ||
} | ||
} | ||
|
||
impl DroppingSlice<'_> { | ||
fn iter(&self) -> std::slice::Iter<'_, i32> { | ||
self.0.iter() | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut v = vec![1, 2, 3, 4]; | ||
for x in DroppingSlice(&*v).iter() { | ||
v.push(*x); //~ERROR | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
error[E0502]: cannot borrow `v` as mutable because it is also borrowed as immutable | ||
--> $DIR/issue-82462.rs:18:9 | ||
| | ||
LL | for x in DroppingSlice(&*v).iter() { | ||
| ------------------ | ||
| | | | ||
| | immutable borrow occurs here | ||
| a temporary with access to the immutable borrow is created here ... | ||
LL | v.push(*x); | ||
| ^^^^^^^^^^ mutable borrow occurs here | ||
LL | break; | ||
LL | } | ||
| - ... and the immutable borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DroppingSlice` | ||
| | ||
help: consider adding semicolon after the expression so its temporaries are dropped sooner, before the local variables declared by the block are dropped | ||
| | ||
LL | }; | ||
| + | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0502`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters