Skip to content

NLL: isolate borrowck errors in Servo dependencies #47596

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

Closed
4 tasks done
SimonSapin opened this issue Jan 19, 2018 · 12 comments
Closed
4 tasks done

NLL: isolate borrowck errors in Servo dependencies #47596

SimonSapin opened this issue Jan 19, 2018 · 12 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@SimonSapin
Copy link
Contributor

SimonSapin commented Jan 19, 2018

UPDATE by @nikomatsakis: In the original issue below, @SimonSapin found several issues when building servo. The goal now is to isolate those issues into standalone test cases and investigate them. Mentoring instructions for doing that isolation can be found here.

The list of tests to be isolated is:

Original issue report

How I got these results:

The relevant code is from crates.io, so easier steps to reproduce might be to build the same crate outside of Servo. And these errors would probably be caught by crater, so they might be already known.

error[E0597]: `*orig.value` does not live long enough
   --> /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/atomic_refcell-0.1.0/src/lib.rs:309:22
    |
309 |             value: f(orig.value),
    |                      ^^^^^^^^^^ borrowed value does not live long enough
...
312 |     }
    |      - borrowed value only lives until here
    |
    = note: borrowed value must be valid for lifetime '_#3r...

error: aborting due to previous error

error: Could not compile `atomic_refcell`.

Caused by:
  process didn't exit successfully: `rustc --crate-name atomic_refcell /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/atomic_refcell-0.1.0/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=2c09db59a67c03f8 -C extra-filename=-2c09db59a67c03f8 --out-dir /home/simon/servo/target/debug/deps -L dependency=/home/simon/servo/target/debug/deps --cap-lints allow -Znll` (exit code: 101)
warning: build failed, waiting for other jobs to finish...
error[E0503]: cannot use `state` because it was mutably borrowed
    --> /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/getopts-0.2.14/src/lib.rs:1008:33
     |
955  |       let mut machine = |cont: &mut bool, (i, c): (usize, char)| {
     |  _______________________-
956  | |         let whitespace = if c.is_whitespace() { Ws }       else { Cr };
957  | |         let limit      = if (i - slice_start + 1) <= lim  { UnderLim } else { OverLim };
958  | |
...    |
1002 | |         *cont
1003 | |     };
     | |_____- borrow of `state` occurs here
...
1008 |       while cont && match state { B | C => true, A => false } {
     |                                   ^ use of borrowed `state`

error: aborting due to previous error

error: Could not compile `getopts`.

Caused by:
  process didn't exit successfully: `rustc --crate-name getopts /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/getopts-0.2.14/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=3a72542378e72657 -C extra-filename=-3a72542378e72657 --out-dir /home/simon/servo/target/debug/deps -L dependency=/home/simon/servo/target/debug/deps --cap-lints allow -Znll` (exit code: 101)
warning: build failed, waiting for other jobs to finish...
error[E0597]: `*self.url` does not live long enough
   --> /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/url-1.6.0/src/form_urlencoded.rs:261:40
    |
261 |     fn finish(self) -> &'a mut ::Url { self.url }
    |                                        ^^^^^^^^  - borrowed value only lives until here
    |                                        |
    |                                        borrowed value does not live long enough
    |
    = note: borrowed value must be valid for lifetime '_#3r...

error: aborting due to previous error

error: Could not compile `url`.

Caused by:
  process didn't exit successfully: `rustc --crate-name url /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/url-1.6.0/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d10e0ca03d0b9ab8 -C extra-filename=-d10e0ca03d0b9ab8 --out-dir /home/simon/servo/target/debug/deps -L dependency=/home/simon/servo/target/debug/deps --extern idna=/home/simon/servo/target/debug/deps/libidna-ee1a4ff6e79abeee.rlib --extern matches=/home/simon/servo/target/debug/deps/libmatches-41f6731261a42312.rlib --extern percent_encoding=/home/simon/servo/target/debug/deps/libpercent_encoding-5b0f452077b83df8.rlib --cap-lints allow -Znll` (exit code: 101)
error[E0506]: cannot assign to `*self.stackTop` because it is borrowed
   --> /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/mozjs-0.1.10/src/rust.rs:524:9
    |
524 |         *self.stackTop = self;
    |         ^^^^^^^^^^^^^^^^^----
    |         |                |
    |         |                borrow of `*self.stackTop` occurs here
    |         assignment to borrowed `*self.stackTop` occurs here

error: aborting due to previous error

error: Could not compile `mozjs`.

Caused by:
  process didn't exit successfully: `rustc --crate-name mozjs /home/simon/.cargo/registry/src/github.com-1ecc6299db9ec823/mozjs-0.1.10/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg feature="mozjs_sys" --cfg feature="promises" -C metadata=8e35027187093d35 -C extra-filename=-8e35027187093d35 --out-dir /home/simon/servo/target/debug/deps -L dependency=/home/simon/servo/target/debug/deps --extern libc=/home/simon/servo/target/debug/deps/liblibc-b118c84ee3630a2a.rlib --extern mozjs_sys=/home/simon/servo/target/debug/deps/libmozjs_sys-d53c511cbe7b3779.rlib --extern lazy_static=/home/simon/servo/target/debug/deps/liblazy_static-72140f6120427c36.rlib --extern log=/home/simon/servo/target/debug/deps/liblog-ae6a67986025a716.rlib --extern num_traits=/home/simon/servo/target/debug/deps/libnum_traits-e126d3e7dde5d2ac.rlib --cap-lints allow -Znll -L native=/home/simon/servo/target/debug/build/mozjs-fe9b4a432325640f/out/lib -l static=jsglue -L native=/home/simon/servo/target/debug/build/mozjs_sys-8afe9ad964841801/out/js/src -L native=/usr/lib/x86_64-linux-gnu` (exit code: 101)
@SimonSapin SimonSapin changed the title NLL errors in Servo dependencies NLL: borrowck errors in Servo dependencies Jan 19, 2018
@aturon
Copy link
Member

aturon commented Jan 19, 2018

cc @rust-lang/wg-compiler-nll

@nikomatsakis nikomatsakis added this to the NLL: Valid code works milestone Jan 19, 2018
@nikomatsakis
Copy link
Contributor

NLL does fix a number of known bugs, so it will take some closer investigation to see whether these failures are expected or not. Thanks for the heads up, @SimonSapin !

@nikomatsakis nikomatsakis added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-NLL Area: Non-lexical lifetimes (NLL) WG-compiler-nll labels Jan 19, 2018
@Aaron1011
Copy link
Member

Minimized version of the url error: https://play.rust-lang.org/?gist=0bd31f0d318c0a4889f720fe54d7979d&version=undefined

The above example compiles if #![feature(nll)] is removed.

@SimonSapin
Copy link
Contributor Author

Thanks @Aaron1011. Deconstructing in a struct pattern (let MyStruct { field, field2 } = self; field instead of self.field) compiles with NLL, so this one looks like a NLL bug rather than a prior bug fixed by NLL.

@TimNN TimNN added C-bug Category: This is a bug. and removed C-bug Category: This is a bug. labels Jan 23, 2018
@nikomatsakis
Copy link
Contributor

Filed @Aaron1011's example as #47703 -- it'd be great to try and minimize the others.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jan 24, 2018

One thing that could help here is trying to isolate the failures that @SimonSapin uncovered. See the issue header for the list of such tests. The procedure would be something like this:

  1. First, check out the source for those versions of those packages. I personally use this script to fetch the sources from cargo -- use like cargo-curl getopts 0.2.14.
  2. Modify the source to add #![feature(nll)] into the lib.rs file.
  3. Try to build. Hopefully, you observe the error.
  4. Try to minimize the error into something standalone.

cc @rust-lang/wg-compiler-nll

@nikomatsakis nikomatsakis changed the title NLL: borrowck errors in Servo dependencies NLL: isolate borrowck errors in Servo dependencies Jan 24, 2018
@nikomatsakis nikomatsakis added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jan 24, 2018
@lqd
Copy link
Member

lqd commented Jan 24, 2018

I think this is a minimized version of the getopts 0.2.14 error: https://play.rust-lang.org/?gist=91237489cb7566627523b81dbb09d917&version=nightly compiles without NLLs

@lqd
Copy link
Member

lqd commented Jan 24, 2018

The atomic_refcell 0.1.0 case looks like the previously minimized error #47703: https://play.rust-lang.org/?gist=5b3934b08dec4d034dc5b00fba8647c3&version=nightly

@nikomatsakis
Copy link
Contributor

@lqd nice!

@lqd
Copy link
Member

lqd commented Jan 24, 2018

@nikomatsakis Just in case Simon's 4th error was forgotten in your list of 3, I also reduced the one in the mozjs 0.1.10 crate: https://play.rust-lang.org/?gist=db23fce76e48bf866b0b8c2f80a50464&version=nightly

(Maybe it wasn't included because an issue already existed)

@nikomatsakis
Copy link
Contributor

@lqd nope, just missed it.

@nikomatsakis
Copy link
Contributor

Gonna close this issue, since we've created subissues for each part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants