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

Polonius borrow checker regression in recent nightlies #57487

Closed
robsmith11 opened this issue Jan 10, 2019 · 2 comments
Closed

Polonius borrow checker regression in recent nightlies #57487

robsmith11 opened this issue Jan 10, 2019 · 2 comments

Comments

@robsmith11
Copy link

robsmith11 commented Jan 10, 2019

The following code was working with -Zpolonius up until rustc 1.33.0-nightly (c0bbc3927 2019-01-03). Since that nightly, the borrow checker fails.

Was this an intentional change? The two borrows are disjoint, so I think it should have been fine.

struct St {
    x:u64,
    v:Vec<u64>,
}

fn main() {
    let mut s = St { x:0, v:Vec::new() };
    s.v.extend((0..1).map(|a| a + s.x));
}
error[E0502]: cannot borrow `s.v` as mutable because it is also borrowed as immutable
 --> src/main.rs:8:5
  |                                                                                                                   
  8 |     s.v.extend((0..1).map(|a| a + s.x));
  |     ^^^^------^^^^^^^^^^^^---^^^^^-^^^^
  |     |   |                 |       |
  |     |   |                 |       first borrow occurs due to use of `s` in closure
  |     |   |                 immutable borrow occurs here
  |     |   immutable borrow later used by call
  |     mutable borrow occurs here

error: aborting due to previous error
@matthewjasper
Copy link
Contributor

Yes, this is intentional. The second borrow is of s (closures can only capture whole variables) and overlaps with the first borrow.

@jonas-schievink
Copy link
Contributor

To clarify some more: There's an accepted RFC that would make the closure borrow s.x instead of the entire s, tracked in #53488

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

No branches or pull requests

3 participants