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

2229: Handle MutBorrow/UniqueImmBorrow better #87676

Merged
merged 1 commit into from
Aug 23, 2021

Conversation

arora-aman
Copy link
Member

@arora-aman arora-aman commented Aug 1, 2021

We only want to use UniqueImmBorrow when the capture place is truncated and we
drop Deref of a MutRef.

r? @nikomatsakis

Fixes: rust-lang/project-rfc-2229#56

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 1, 2021
We only want to use UniqueImmBorrow when the capture place is truncated and we
drop Deref of a MutRef.

r? @nikomatsakis
@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 17, 2021
@@ -1843,7 +1885,7 @@ fn adjust_for_move_closure<'tcx>(
_ if first_deref.is_some() => {
let place = match first_deref {
Some(idx) => {
place.projections.truncate(idx);
let (place, _) = truncate_place_to_len(place, kind, idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

why don't we care about kind here?

Copy link
Contributor

Choose a reason for hiding this comment

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

is this equivalent to just calling truncate(idx)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes can just do a regular truncate here because we instantly replace the kind with ByValue. I just used the function for consistency.

/// contained `Deref` of `&mut`.
fn truncate_place_to_len(
mut place: Place<'tcx>,
curr_mode: ty::UpvarCapture<'tcx>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we want this to be

truncate_place_to_len(mut place: Place<'tcx>, curr_mode: &mut ty::UpvarCapture<'tcx>, len: usize)

or even

truncate_place_to_len(place: &mut Place<'tcx>, curr_mode: &mut ty::UpvarCapture<'tcx>, len: usize)

It seemed like a lot of the callers (almost all) were doing

let (..., mode) = truncate_place_to_len(place, curr_mode, ...);
curr_mode = mode;

which is a bit silly.

Copy link
Member Author

Choose a reason for hiding this comment

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

My thoughts:

  • Looking at just the function all it's not directly evident that the mode has changed, might need a better name.
  • Some codepaths don't really have a &mut Place (eg: within Delegate -- we need to handle repr packed) so that might need adding a line to create an owned Place variable.

Can we use unstable features? #71126 looks is near stabilization and the syntax is what I'd prefer, i.e. directly update the variables than destructure and then assign

Copy link
Contributor

Choose a reason for hiding this comment

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

We are permitted to use unstable features, yes.

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2021

📌 Commit 8e89971 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 23, 2021
@bors
Copy link
Contributor

bors commented Aug 23, 2021

⌛ Testing commit 8e89971 with merge 9583fd1...

@bors
Copy link
Contributor

bors commented Aug 23, 2021

☀️ Test successful - checks-actions
Approved by: nikomatsakis
Pushing 9583fd1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 23, 2021
@bors bors merged commit 9583fd1 into rust-lang:master Aug 23, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Code sometimes uses UniqueImmBorrow and not MutBorrow
6 participants