Skip to content
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

Lift $dst outside the closure in write! #12240

Closed
wants to merge 1 commit into from

Conversation

alexcrichton
Copy link
Member

If you were writing to something along the lines of self.foo then with the new
closure rules it meant that you were borrowing self for the entirety of the
closure, meaning that you couldn't format other fields of self at the same
time as writing to a buffer contained in self.

By lifting the borrow outside of the closure the borrow checker can better
understand that you're only borrowing one of the fields at a time. This had to
use type ascription as well in order to preserve trait object coercions.

other: &'a str,
}

fn uh_oh(foo: Foo) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't want it called uh_oh any more now that you've fixed it so it works!

@chris-morgan
Copy link
Member

LGTM (replacing the macro fixed the problem in rust-http).

If you were writing to something along the lines of `self.foo` then with the new
closure rules it meant that you were borrowing `self` for the entirety of the
closure, meaning that you couldn't format other fields of `self` at the same
time as writing to a buffer contained in `self`.

By lifting the borrow outside of the closure the borrow checker can better
understand that you're only borrowing one of the fields at a time. This had to
use type ascription as well in order to preserve trait object coercions.
@alexcrichton alexcrichton deleted the fix-write-macro branch February 14, 2014 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants