-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix end region emission order #44129
Fix end region emission order #44129
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Can you have a test that shows how this fits with the destruction code extent? Maybe even in the same test? It should be
|
r=me modulo @arielb1's concern |
☔ The latest upstream changes (presumably #43076) made this pull request unmergeable. Please resolve the merge conflicts. |
369e87d
to
96e4f35
Compare
Sorry its taking me so long to finish this off. I spent a while trying to create a case matching @arielb1's expectation. Now I think I have one, but I also am not sure whether the outline @arielb1 gave is what we should actually want to see in practice. Here is some input code I've come up with: fn main() {
// This case illustrates one particular ordering of interest:
D1(&S1("tmp"));
}
#[derive(Debug)]
struct S1(&'static str);
#[derive(Debug)]
struct D1<'a>(&'a S1);
impl<'a> Drop for D1<'a> {
fn drop(&mut self) {
println!("D1({:?})", self.0);
}
} Here is the output MIR (compiled via:
So, here's my problem: I agree that But it should precede the ... (Also, I just realized that this code actually only started compiling relatively recently; on the current stable, it is rejected with a suggestion that the |
I think what I would expect is that we would run the qualification pass after construction, and hence wind up removing |
Your example only compiles because of rvalue promotion. An rvalue-promotion version (or this one, on stable) errors as it should - today's borrowck basically puts the fn main() {
// This case illustrates one particular ordering of interest:
let x = "tmp";
D1(&S1(x)); //~ ERROR
}
#[derive(Debug)]
struct S1(&'static str);
#[derive(Debug)]
struct D1<'a>(&'a S1);
impl<'a> Drop for D1<'a> {
fn drop(&mut self) {
println!("D1({:?})", self.0);
}
} Also, you can easily have fn main() {
D1((&D1(&S1("red")), &S1("tmp"), &D1(&S1("herring"))).1);
} In which case there is no "between the drop and storagedead" place. Therefore, I prefer having the drop & storagedead as 1 unit and placing the |
I'll also note that moving the |
@arielb1 ... okay, but isn't that in conflict with the property (taken from #43481 (comment) ):
|
@arielb1 or maybe I misunderstand (once again)? Are you saying that we will enforce the property, because the compiler will reject such code? |
Thats... what the borrow-check does. Or at least what it's supposed to do. You can't have a live borrow to something while you |
@arielb1 okay, I was confused because I thought you were suggesting an ordering for {Drop,StorageDead,EndRegion} that you intended to be legal to the borrowck in cases like this. |
96e4f35
to
4a7c28c
Compare
@bors r=nmatsakis |
📌 Commit 4a7c28c has been approved by |
⌛ Testing commit 4a7c28c9b1f956fb7577bd118adb9b2823f37bfe with merge 8318fdad5733a80e7d7449bfdbc08bd42cc0a47c... |
💔 Test failed - status-travis |
@bors retry
|
⌛ Testing commit 4a7c28c9b1f956fb7577bd118adb9b2823f37bfe with merge 19db440bb17f57e851875ab641283c24abc621f2... |
💔 Test failed - status-travis |
|
⌛ Testing commit 4a7c28c9b1f956fb7577bd118adb9b2823f37bfe with merge 055f72be4a23c82a6a4d6278440439b1fa3a69f3... |
💔 Test failed - status-travis |
⌛ Testing commit 4a7c28c9b1f956fb7577bd118adb9b2823f37bfe with merge 05446c7ffd17549af517b5bed93fb5066910a430... |
💔 Test failed - status-travis |
|
☔ The latest upstream changes (presumably #44171) made this pull request unmergeable. Please resolve the merge conflicts. |
@pnkfelix merge conflict :( |
🔒 Merge conflict |
4a7c28c
to
e2f00fc
Compare
@bors r=nmatsakis |
📌 Commit e2f00fc has been approved by |
@bors r- Failure seems related?
|
☔ The latest upstream changes (presumably #44249) made this pull request unmergeable. Please resolve the merge conflicts. |
…or a scope. (The idea is that the StorageDead marks the point where the memory can be deallocated, and the EndRegion is marking where borrows of that memory can no longer legally exist.)
Driveby fix to end_region_9.rs; it was missing END marker and was therefore always passing (regardless of output correctness).
e2f00fc
to
5fa0b66
Compare
Thanks @aidanhs sorry about that! |
@bors r=nmatsakis |
📌 Commit 5fa0b66 has been approved by |
…sakis Fix end region emission order Fix #43481
☀️ Test successful - status-appveyor, status-travis |
Fix #43481