-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 lifetime rules for 'if' conditions #36029
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test an example where we fail to infer the type parameter H. This |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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].