Fix lifetime rules for 'if' conditions#36029
Conversation
|
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
This doesn't seem to belong here.
|
The issue title refers to fixing both EDIT: reading the issue, its clear that only thing this PR ought to be fixing is |
|
Whoops, I made a couple of stupids, now it should look fine. Not sure if it behaves fine though. |
|
@bors r+ |
|
📌 Commit 4853456 has been approved by |
Fix lifetime rules for 'if' conditions Fixes #12033. Changes the temporary scope rules to make the condition of an if-then-else a terminating scope. This is a [breaking-change].
|
To explain how this can be a breaking-change, we can look at the The opposite can be produced by having a local variable borrow the temporary instead: struct Foo;
impl Foo {
fn save<'a>(&'a self, dest: &mut &'a Foo) -> bool {
*dest = self;
true
}
}
fn main() {
let mut dest = &Foo;
if Foo.save(&mut dest) {} else {}
}This example compiles before this PR, but not if we remove EDIT: The other breaking change here is destructor ordering, which affects all the code using |
Fixes #12033.
Changes the temporary scope rules to make the condition of an if-then-else a terminating scope. This is a [breaking-change].