librustc: WIP patch for upgrading the way rvalues are treated. #16009
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIP. Do not merge.
@nikomatsakis I'd like to get your feedback on this. I've implemented a patch which fixes #14587, but it has some nasty fallout in other parts of the codebase.
I first tried to make all rvalues treated like lvalues. This ran into problems with method chaining:
foo.bar().baz()
would not work anymore ifbaz
required&mut self
, as it thought it was a double borrow. I believe this is because of the rvalue temporary rules.The next thing, which is in this patch, was to formulate the notion of "aliasable rvalues". These are rvalues that could be aliasable because they're about to be unpacked into a pattern. Local initializers, match values, and for loop heads fall into this list. This causes a few strange errors:
This may be related to the rvalue scope extension rules. I haven't dug into that to see whether it's the case.
Any thoughts as to the right way to go here?