Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Code sometimes uses UniqueImmBorrow and not MutBorrow #56

Closed
nikomatsakis opened this issue Jul 11, 2021 · 3 comments · Fixed by rust-lang/rust#87676
Closed

Code sometimes uses UniqueImmBorrow and not MutBorrow #56

nikomatsakis opened this issue Jul 11, 2021 · 3 comments · Fixed by rust-lang/rust#87676

Comments

@nikomatsakis
Copy link
Contributor

Discussion here:

rust-lang/rust#86995 (comment)

@nikomatsakis
Copy link
Contributor Author

Relevant code:

https://github.com/rust-lang/rust/blob/efeea79a6bb6867b220471e0396b82b6b68ebc4c/compiler/rustc_typeck/src/check/upvar.rs#L1495-L1503

The problem here is that this code is still oriented around a single variable, and not a place.

@nikomatsakis
Copy link
Contributor Author

Given foo: &mut (u32, u32), there are a few scenarios to consider:

  • If the closure mutates foo.0 but we wind up capturing foo, we only need a "unique" borrow of foo.
  • If the closure mutates foo.0 and we capture foo.0, we need a "mut" borrow.

In short, the need for a "mut" borrow depends on what data we ultimately capture.

@nikomatsakis nikomatsakis added this to the Polish complete milestone Jul 11, 2021
@arora-aman
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants