-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Desugar fn(&mut self)
to fn(mut self: &mut self)
#50014
Conversation
In order to improve ergonomics, desugar `&mut self` as a mutable binding, allowing people to reborrow `self` as mutable borrow in the body of the method.
Silly question: Does this mean I can now accidentally do this? fn foo(&mut self, other: &mut Self) {
self = other;
} |
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@scottmcm correct |
Our story around "immutably bound mutable references", "mutably bound immutable references", "immutably bound Edit: or you can write |
Or you can actually write |
Fun fact: we'd need this much more often if not the secret closure borrowing mode |
In any case, if we want to do this change, it should first go through the RFC process IMO :) |
@rust-lang/lang, @rust-lang/compiler: How do you want to move forward with this? Should this go through the RFC process? Or just an FCP here? |
I think there was already an RFC that proposed having additional types for |
I would like to hear from @nikomatsakis on his thoughts. I've come around to maybe only provide a suggestion for |
Hmm. I agree that permitting |
Seems like we are not going to do this, right? |
@nikomatsakis If we don't (which I also lean towards), we should provide a suggestion. If we do, what should we suggest then? |
We could try to detect if the program only needs to use That is a little bit ugly to do in the HIR, but doable. It should be easier in MIR, which is all for the better, given that we are moving to MIR borrowck. |
I like @arielb1's suggestion. Indeed, I suspect that often just |
@nikomatsakis the problem with suggesting passing ownership is that in order to not be misleading we would need to verify the usage of |
@estebank yes, sounds reasonable. Shall we close this PR? |
In order to improve ergonomics, desugar
&mut self
to a mutable binding instead of an immutable binding, allowing people to re-borrowself
as mutable borrow in the body of the method.This implements the suggestion in https://github.com/rust-lang/rust/pull/47818/files#r164512390, which allows
rustc
to start accepting the code in #47774.r? @nikomatsakis
CC @rust-lang/compiler @rust-lang/lang
Creating the PR in order to coalesce the impact and FCP conversation around the code changes themselves.