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

Incremental compilation does not account for changes to -Zpolonius #79316

Closed
shepmaster opened this issue Nov 22, 2020 · 1 comment · Fixed by #79397
Closed

Incremental compilation does not account for changes to -Zpolonius #79316

shepmaster opened this issue Nov 22, 2020 · 1 comment · Fixed by #79397
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shepmaster
Copy link
Member

I tried this code:

/// Insert a new data element at a given key.
pub fn insert<'a, K: Eq, V>(this: &'a mut Vec<(K, V)>, key: K, val: V) -> &'a mut V {
    for (key1, val1) in &mut *this {
        if key == *key1 {
            return val1;
        }
    }
    let this = &mut *this;
    this.push((key, val));
    &mut this.last_mut().unwrap().1
}

fn main() {
    let mut things = vec![(1, 2), (3, 4)];

    let v = insert(&mut things, 1, 2);
    println!("{} ({:p})", v, v);

    let v = insert(&mut things, 1, 2);
    println!("{} ({:p})", v, v);

    let v = insert(&mut things, 5, 6);
    println!("{} ({:p})", v, v);

    let v = insert(&mut things, 5, 6);
    println!("{} ({:p})", v, v);
}

I expected this to fail when not compiled with -Zpolonius, but it does compile if we previously built with -Zpolonius:

% RUSTFLAGS='' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
error[E0499]: cannot borrow `*this` as mutable more than once at a time
 --> src/main.rs:8:16
  |
2 | pub fn insert<'a, K: Eq, V>(this: &'a mut Vec<(K, V)>, key: K, val: V) -> &'a mut V {
  |               -- lifetime `'a` defined here
3 |     for (key1, val1) in &mut *this {
  |                         ---------- first mutable borrow occurs here
4 |         if key == *key1 {
5 |             return val1;
  |                    ---- returning this value requires that `*this` is borrowed for `'a`
...
8 |     let this = &mut *this;
  |                ^^^^^^^^^^ second mutable borrow occurs here

% RUSTFLAGS='-Zpolonius' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s

% RUSTFLAGS='' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s

If I disable incremental compilation, this does not occur:

[profile.dev]
incremental = false
% RUSTFLAGS='' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
error[E0499]: cannot borrow `*this` as mutable more than once at a time
 --> src/main.rs:8:16
  |
2 | pub fn insert<'a, K: Eq, V>(this: &'a mut Vec<(K, V)>, key: K, val: V) -> &'a mut V {
  |               -- lifetime `'a` defined here
3 |     for (key1, val1) in &mut *this {
  |                         ---------- first mutable borrow occurs here
4 |         if key == *key1 {
5 |             return val1;
  |                    ---- returning this value requires that `*this` is borrowed for `'a`
...
8 |     let this = &mut *this;
  |                ^^^^^^^^^^ second mutable borrow occurs here

% RUSTFLAGS='-Zpolonius' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
    Finished dev [unoptimized + debuginfo] target(s) in 0.32s

% RUSTFLAGS='' cargo +nightly build
   Compiling p v0.1.0 (/private/tmp/p)
error[E0499]: cannot borrow `*this` as mutable more than once at a time
 --> src/main.rs:8:16
  |
2 | pub fn insert<'a, K: Eq, V>(this: &'a mut Vec<(K, V)>, key: K, val: V) -> &'a mut V {
  |               -- lifetime `'a` defined here
3 |     for (key1, val1) in &mut *this {
  |                         ---------- first mutable borrow occurs here
4 |         if key == *key1 {
5 |             return val1;
  |                    ---- returning this value requires that `*this` is borrowed for `'a`
...
8 |     let this = &mut *this;
  |                ^^^^^^^^^^ second mutable borrow occurs here

Meta

% rustc +nightly --version --verbose
rustc 1.50.0-nightly (da3846948 2020-11-21)
binary: rustc
commit-hash: da384694807172f0ca40eca2e49a11688aba6e93
commit-date: 2020-11-21
host: x86_64-apple-darwin
release: 1.50.0-nightly
@shepmaster shepmaster added A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. labels Nov 22, 2020
@jonas-schievink
Copy link
Contributor

This needs to be changed to TRACKED:

polonius: bool = (false, parse_bool, [UNTRACKED],
"enable polonius-based borrow-checker (default: no)"),

@jonas-schievink jonas-schievink added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. labels Nov 22, 2020
@camelid camelid self-assigned this Nov 25, 2020
@bors bors closed this as completed in 20dcbf0 Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants