Skip to content

NLL (MIR borrowck) regression in Servo’s layout crate #48358

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
SimonSapin opened this issue Feb 19, 2018 · 9 comments
Closed

NLL (MIR borrowck) regression in Servo’s layout crate #48358

SimonSapin opened this issue Feb 19, 2018 · 9 comments
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.

Comments

@SimonSapin
Copy link
Contributor

In servo/servo@be902d5 (current master), with rustc 1.25.0-nightly (27a046e 2018-02-18)

cargo +nightly-2018-02-19 rustc -p layout: OK

cargo +nightly-2018-02-19 rustc -p layout -- -Zborrowck=mir:

   Compiling layout v0.0.1 (file:///home/simon/servo/components/layout)
error[E0502]: cannot borrow `self.column_computed_inline_sizes` as immutable because it is also borrowed as mutable
   --> components/layout/table.rs:421:33
    |
419 |                         self.column_computed_inline_sizes[index].size +=
    |                         --------------------------------- mutable borrow occurs here
420 |                             remaining_inline_size.scale_by(
421 |                                 self.column_computed_inline_sizes[index].size.0 as f32 / total_minimum_size);
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here             - mutable borrow ends here

error[E0503]: cannot use `unscanned_text_fragment_info.selection` because it was mutably borrowed
   --> components/layout/text.rs:527:40
    |
515 |                 Some(ref mut selection) if selection.begin() >= offset => {
    |                      ----------------- borrow of `unscanned_text_fragment_info.selection.0` occurs here
...
527 |                     selection_before = unscanned_text_fragment_info.selection;
    |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of borrowed `unscanned_text_fragment_info.selection.0`

error[E0506]: cannot assign to `unscanned_text_fragment_info.selection` because it is borrowed
   --> components/layout/text.rs:528:21
    |
515 |                 Some(ref mut selection) if selection.begin() >= offset => {
    |                      ----------------- borrow of `unscanned_text_fragment_info.selection` occurs here
...
528 |                     unscanned_text_fragment_info.selection = None;
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `unscanned_text_fragment_info.selection` occurs here

error[E0499]: cannot borrow `unscanned_text_fragment_info.selection.0` as mutable more than once at a time
   --> components/layout/text.rs:520:22
    |
515 |                 Some(ref mut selection) if selection.begin() >= offset => {
    |                      ----------------- first mutable borrow occurs here
...
520 |                 Some(ref mut selection) if selection.end() > offset => {
    |                      ^^^^^^^^^^^^^^^^^ second mutable borrow occurs here
...
530 |             };
    |             - first borrow ends here

error: aborting due to 4 previous errors

error: Could not compile `layout`.

cargo +nightly-2018-02-19 rustc -p layout -- -Znll:

   Compiling layout v0.0.1 (file:///home/simon/servo/components/layout)
error[E0502]: cannot borrow `self.column_computed_inline_sizes` as immutable because it is also borrowed as mutable
   --> components/layout/table.rs:421:33
    |
419 |                         self.column_computed_inline_sizes[index].size +=
    |                         --------------------------------- mutable borrow occurs here
420 |                             remaining_inline_size.scale_by(
421 |                                 self.column_computed_inline_sizes[index].size.0 as f32 / total_minimum_size);
    |                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ immutable borrow occurs here

error: aborting due to previous error

error: Could not compile `layout`.
@Aaron1011
Copy link
Member

I strongly suspect that the first error is the same as #48129

@pietroalbini pietroalbini added A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug. WG-compiler-nll labels Feb 20, 2018
@nikomatsakis
Copy link
Contributor

@SimonSapin now that #48129 is fixed, can you validate whether this error still occurs?

@nikomatsakis nikomatsakis added this to the NLL: Valid code works milestone Mar 14, 2018
@nikomatsakis nikomatsakis added the NLL-complete Working towards the "valid code works" goal label Mar 14, 2018
@SimonSapin
Copy link
Contributor Author

Yes, the output is unchanged in rustc 1.26.0-nightly (2789b06 2018-03-06). (The latest nightly is a bit old but it does contain #48197 which closed #48129.)

@nikomatsakis
Copy link
Contributor

I think this may be a legitimate bug fix. Does self.column_computed_inline_sizes[index] implement IndexMut etc?

@SimonSapin
Copy link
Contributor Author

column_computed_inline_sizes is a Vec.

@nikomatsakis
Copy link
Contributor

@SimonSapin so that would be "yes" =)

@nikomatsakis
Copy link
Contributor

In short, this looks like a dup of #47349 -- @SimonSapin do you agree?

@nikomatsakis nikomatsakis added NLL-deferred and removed NLL-complete Working towards the "valid code works" goal labels Apr 3, 2018
@nikomatsakis
Copy link
Contributor

I'm retagging this as NLL-deferred -- I would like to dig in deeper to verify that it is indeed an expected error at some point, but I think it looks quite likely.

@nikomatsakis nikomatsakis removed this from the NLL: Valid code works milestone Jul 24, 2018
@SimonSapin
Copy link
Contributor Author

I’ve changed the Servo code in servo/servo#21356 to work around this error. Yes, this looks similar enough to #47349 that it’s probably fine to close as duplicate.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants