Skip to content

Remove the implementation of DerefMut for FlowRef. #6503

Closed as not planned
Closed as not planned

Description

@Ms2ger

FlowRef is basically Arc<Flow>, so DerefMut trivially exposes aliased &mut Flows.

CC @SimonSapin @pcwalton

Activity

  1. added
    I-safety
    on Jun 27, 2015
  2. SimonSapin commented on Jul 15, 2015

    @SimonSapin
    Member

    I tried just removing the DerefMut impl. After getting past a few initial errors, I got a bunch more :(

       Compiling layout v0.0.1 (file:///home/simon/projects/servo/components/servo)
    /home/simon/projects/servo/components/layout/construct.rs:444:31: 444:46 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:444             let inline_flow = inline_flow_ref.as_inline();
                                                                                                ^~~~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/construct.rs:772:40: 772:44 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:772                         let kid_node = flow.as_block().fragment.node;
                                                                                                         ^~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:750:9: 823:10 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:773:41: 773:45 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:773                         let kid_style = flow.as_block().fragment.style.clone();
                                                                                                          ^~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:750:9: 823:10 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:774:50: 774:54 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:774                         let kid_restyle_damage = flow.as_block().fragment.restyle_damage;
                                                                                                                   ^~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:750:9: 823:10 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:962:25: 962:33 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:962                         kid_flow.as_block()
                                                                                          ^~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:958:9: 972:10 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1046:35: 1046:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1046         let is_fixed_positioned = wrapper_flow.as_block().is_fixed();
                                                                                                     ^~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/construct.rs:1262:37: 1262:43 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1262                 flow::mut_base(&mut **flow).restyle_damage.insert(damage);
                                                                                                       ^~~~~~
    /home/simon/projects/servo/components/layout/construct.rs:1263:17: 1263:21 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1263                 flow.repair_style_and_bubble_inline_sizes(&style);
                                                                                   ^~~~
    /home/simon/projects/servo/components/layout/construct.rs:1277:49: 1277:80 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1277                             flow::mut_base(&mut *inline_block_fragment.flow_ref).restyle_damage
                                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1280:29: 1280:59 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1280                             inline_block_fragment.flow_ref
                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1285:49: 1285:96 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1285                             flow::mut_base(&mut *inline_absolute_hypothetical_fragment.flow_ref)
                                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1288:29: 1289:42 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1288                             inline_absolute_hypothetical_fragment
    /home/simon/projects/servo/components/layout/construct.rs:1289                                 .flow_ref
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1293:49: 1293:83 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1293                             flow::mut_base(&mut *inline_absolute_fragment.flow_ref).restyle_damage
                                                                                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1296:29: 1296:62 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1296                             inline_absolute_fragment.flow_ref
                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/construct.rs:1272:17: 1306:18 note: expansion site
    /home/simon/projects/servo/components/layout/construct.rs:1587:48: 1587:58 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1587             let kid_base = flow::mut_base(&mut *new_child);
                                                                                                                  ^~~~~~~~~~
    /home/simon/projects/servo/components/layout/construct.rs:1591:40: 1591:46 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1591         let base = flow::mut_base(&mut **self);
                                                                                                          ^~~~~~
    /home/simon/projects/servo/components/layout/construct.rs:1606:13: 1606:17 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/construct.rs:1606             self.bubble_inline_sizes()
                                                                               ^~~~
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1673:43: 1673:63 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1673                     let block_flow = &mut *block_flow.flow_ref;
                                                                                                                        ^~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1654:9: 1689:10 note: expansion site
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1678:43: 1678:63 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1678                     let block_flow = &mut *block_flow.flow_ref;
                                                                                                                        ^~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1654:9: 1689:10 note: expansion site
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1683:43: 1683:63 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1683                     let block_flow = &mut *block_flow.flow_ref;
                                                                                                                        ^~~~~~~~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/display_list_builder.rs:1654:9: 1689:10 note: expansion site
    /home/simon/projects/servo/components/layout/flow.rs:747:42: 747:48 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/flow.rs:747         self.iter.next().map(|flow| &mut **flow)
                                                                                                      ^~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/flow.rs:747:30: 747:48 note: expansion site
    /home/simon/projects/servo/components/layout/flow.rs:1351:34: 1351:40 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/flow.rs:1351         let base = mut_base(&mut **self);
                                                                                               ^~~~~~
    /home/simon/projects/servo/components/layout/flow_list.rs:36:48: 36:54 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/flow_list.rs:36         self.flows.front_mut().map(|head| &mut **head)
                                                                                                                ^~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/flow_list.rs:36:36: 36:54 note: expansion site
    /home/simon/projects/servo/components/layout/flow_list.rs:49:47: 49:53 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/flow_list.rs:49         self.flows.back_mut().map(|tail| &mut **tail)
                                                                                                               ^~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/flow_list.rs:49:35: 49:53 note: expansion site
    /home/simon/projects/servo/components/layout/flow_list.rs:127:37: 127:40 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/flow_list.rs:127         self.it.next().map(|x| &mut **x)
                                                                                                      ^~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/flow_list.rs:127:28: 127:40 note: expansion site
    /home/simon/projects/servo/components/layout/fragment.rs:1273:34: 1273:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1273                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1277:34: 1277:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1277                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1651:34: 1651:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1651                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1659:34: 1659:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1659                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1667:34: 1667:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1667                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1771:34: 1771:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1771                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1777:34: 1777:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1777                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1782:34: 1782:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1782                 let block_flow = info.flow_ref.as_block();
                                                                                                   ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1902:30: 1902:56 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1902             let block_flow = inline_block_info.flow_ref.as_block();
                                                                                               ^~~~~~~~~~~~~~~~~~~~~~~~~~
    note: in expansion of if let expansion
    /home/simon/projects/servo/components/layout/fragment.rs:1901:9: 1907:10 note: expansion site
    /home/simon/projects/servo/components/layout/fragment.rs:1914:17: 1914:30 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1914                 info.flow_ref.update_late_computed_inline_position_if_necessary(position)
                                                                                  ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/fragment.rs:1924:17: 1924:30 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/fragment.rs:1924                 info.flow_ref.update_late_computed_block_position_if_necessary(position)
                                                                                  ^~~~~~~~~~~~~
    /home/simon/projects/servo/components/layout/layout_task.rs:764:9: 764:13 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:764         flow.mark_as_root();
                                                                            ^~~~
    /home/simon/projects/servo/components/layout/layout_task.rs:858:33: 858:46 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:858             flow::mut_base(&mut **layout_root).stacking_relative_position =
                                                                                                    ^~~~~~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:854:17: 918:10 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:862:33: 862:46 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:862             flow::mut_base(&mut **layout_root).clip =
                                                                                                    ^~~~~~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:854:17: 918:10 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:882:81: 882:94 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:882                 let root_background_color = get_root_flow_background_color(&mut **layout_root);
                                                                                                                                                    ^~~~~~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:854:17: 918:10 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:888:37: 888:50 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:888                 flow::mut_base(&mut **layout_root).display_list_building_result
                                                                                                        ^~~~~~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:854:17: 918:10 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:981:51: 981:56 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:981                 LayoutTask::reflow_all_nodes(&mut *flow);
                                                                                                                      ^~~~~
    note: in expansion of if let expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:980:13: 982:14 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:1149:53: 1149:62 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:1149             if opts::get().nonincremental_layout || root_flow.compute_layout_damage()
                                                                                                                         ^~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:1148:17: 1153:10 note: expansion site
    /home/simon/projects/servo/components/layout/layout_task.rs:1151:17: 1151:26 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/layout_task.rs:1151                 root_flow.reflow_entire_document()
                                                                                     ^~~~~~~~~
    note: in expansion of closure expansion
    /home/simon/projects/servo/components/layout/layout_task.rs:1148:17: 1153:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1494:41: 1494:55 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1494                     flow::mut_base(&mut *info.flow_ref).clip = clip;
                                                                                                        ^~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1496:38: 1496:51 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1496                     let block_flow = info.flow_ref.as_block();
                                                                                                     ^~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1504:41: 1504:55 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1504                     flow::mut_base(&mut *info.flow_ref).clip = clip;
                                                                                                        ^~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1505:38: 1505:51 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1505                     let block_flow = info.flow_ref.as_block();
                                                                                                     ^~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1514:41: 1514:55 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1514                     flow::mut_base(&mut *info.flow_ref).clip = clip;
                                                                                                        ^~~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/inline.rs:1516:38: 1516:51 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/inline.rs:1516                     let block_flow = info.flow_ref.as_block();
                                                                                                     ^~~~~~~~~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/inline.rs:1480:9: 1533:10 note: expansion site
    /home/simon/projects/servo/components/layout/parallel.rs:249:45: 249:51 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:249                 if self.should_process(&mut **flow) {
                                                                                                             ^~~~~~
    /home/simon/projects/servo/components/layout/parallel.rs:250:39: 250:45 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:250                     self.process(&mut **flow);
                                                                                                       ^~~~~~
    /home/simon/projects/servo/components/layout/parallel.rs:254:48: 254:54 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:254                 let base = flow::mut_base(&mut **flow);
                                                                                                                ^~~~~~
    /home/simon/projects/servo/components/layout/parallel.rs:271:55: 271:63 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:271                 let parent_base = flow::mut_base(&mut **parent);
                                                                                                                       ^~~~~~~~
    /home/simon/projects/servo/components/layout/parallel.rs:306:41: 306:47 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:306                     flow::mut_base(&mut **flow).thread_id = proxy.worker_index();
                                                                                                         ^~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/parallel.rs:299:9: 325:10 note: expansion site
    /home/simon/projects/servo/components/layout/parallel.rs:309:45: 309:51 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:309                 if self.should_process(&mut **flow) {
                                                                                                             ^~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/parallel.rs:299:9: 325:10 note: expansion site
    /home/simon/projects/servo/components/layout/parallel.rs:311:39: 311:45 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:311                     self.process(&mut **flow);
                                                                                                       ^~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/parallel.rs:299:9: 325:10 note: expansion site
    /home/simon/projects/servo/components/layout/parallel.rs:315:50: 315:56 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:315                 for kid in flow::child_iter(&mut **flow) {
                                                                                                                  ^~~~~~
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/parallel.rs:315:17: 318:18 note: expansion site
    note: in expansion of for loop expansion
    /home/simon/projects/servo/components/layout/parallel.rs:299:9: 325:10 note: expansion site
    /home/simon/projects/servo/components/layout/parallel.rs:478:9: 478:13 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/parallel.rs:478         root.traverse_postorder(&bubble_inline_sizes);
                                                                         ^~~~
    /home/simon/projects/servo/components/layout/sequential.rs:58:15: 58:21 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/sequential.rs:58     doit(&mut **root, 0, &mut traversal)
                                                                                ^~~~~~
    /home/simon/projects/servo/components/layout/sequential.rs:81:21: 81:27 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/sequential.rs:81     let root = &mut **root;
                                                                                      ^~~~~~
    /home/simon/projects/servo/components/layout/sequential.rs:119:15: 119:21 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/sequential.rs:119     doit(&mut **root, compute_absolute_positions, build_display_list);
                                                                                 ^~~~~~
    /home/simon/projects/servo/components/layout/sequential.rs:142:15: 142:21 error: cannot borrow immutable borrowed content as mutable
    /home/simon/projects/servo/components/layout/sequential.rs:142     doit(&mut **root, iterator, &ZERO_POINT);
                                                                                 ^~~~~~
    error: aborting due to 63 previous errors
    Could not compile `layout`.
  3. metajack commented on Jul 15, 2015

    @metajack
    Collaborator

    This can't be easily removed. I tried this as well and gave up. The core issue is that during flow construction we need to mutate these unsafely, but once hte flows are constructed, we use them without DerefMut. We want to avoid constructing the tree in one data type and then converting it to another that is then shared. I'm not sure the best way to get around this. @pcwalton may have some thoughts; he wrote the original code.

  4. Ms2ger commented on Jul 15, 2015

    @Ms2ger
    ContributorAuthor

    get_mut with a runtime refcount check?

  5. SimonSapin commented on Jul 15, 2015

    @SimonSapin
    Member

    So Arc<RwLock>?

  6. metajack commented on Jul 15, 2015

    @metajack
    Collaborator

    @Ms2ger That may work. I think get_mut was not available on Arc when I tried this, although I had a discussion with @aturon about this in Whistlier, and perhaps they've added it now.

    @SimonSapin I don't think we're willing to pay the price of locking. All the fancy unsafety in layout is designed around Flows, and slowing down Flow access is probably a non-starter.

    In any case, I agree this needs to be done; I was only trying to point out that it's more difficult than it seems at first.

  7. SimonSapin commented on Jul 15, 2015

    @SimonSapin
    Member

    Ah, yes, refcount for mutable access made me think of RefCell, which in multi-thread translates to RwLock, but you’re right that we can have something like Arc::get_mut instead.

    Is there a reason not to use Arc directly? Arc::get_mut is still unstable but now un-deprecated. (The data race has been solved in rust-lang/rust#26610.)

  8. metajack commented on Jul 15, 2015

    @metajack
    Collaborator

    Using Arc directly is the desired outcome. How to reconcile this with flow construction is an exercise no one has completed yet. I'm pretty sure when I tried was right after they removed get_mut but before they fixed the race and put it back. It's worth trying again.

  9. metajack commented on Jul 15, 2015

    @metajack
    Collaborator

    @SimonSapin It should be noted that @aturon was interested in helping us solve this, so if get_mut is insufficient, we should definitely talk to the Rust team about what options we have.

  10. aturon commented on Jul 16, 2015

    @aturon

    Yep, happy to help further on this, just let me know what the blockers are.

  11. Ms2ger commented on Jul 23, 2015

    @Ms2ger
    ContributorAuthor

    get_mut isn't going to cut it; we do call into this even with refcounts greater than one. This is plain and simple UB.

  12. metajack commented on Jul 27, 2015

    @metajack
    Collaborator

    @Ms2ger What is UB?

  13. jdm commented on Jul 27, 2015

    @jdm
    Member

    Undefined behaviour.

  14. 3 remaining items

  15. eefriedman commented on Sep 26, 2015

    @eefriedman
    Contributor

    Some additional observations:

    1. Calling flow_ref::deref_mut doesn't lead to undefined behavior unless the Arc in question is dereferenced again while the return value of deref_mut is still in scope. Arc::get_mut dynamically proves the safety using the reference count, but you can use a different invariant if you're willing to write unsafe code.
    2. The current implementation of reflow depends on a tree property to make its usage essentially safe; using Box instead of Arc, you can implement something similar to the current flow tree without using any unsafe code. (As far as I can tell, there are currently three places which violate the tree-ness of flows in layout: ContainingBlockLink, layout_debug, and PrivateLayoutData. ContainingBlockLink is essentially a shortcut to avoid the cost of propagating certain reflow information down the tree, layout_debug is just for debugging, and PrivateLayoutData is never used during reflow because the DOM can't be accessed during layout.)
    3. I think the usage of ContainingBlockLink alongside flow_ref::deref_mut leads to undefined behavior, although probably not in a way the compiler will actually ever break. (Strictly speaking, when an mutable reference is in scope, all accesses to the referenced data must go through that reference.)
    4. Given that Flows form a tree, there's very little benefit to making them Arcs as opposed to Boxes.
  16. nox commented on Jun 6, 2016

    @nox
    Contributor

    This starts warning:

    warning: lifetime parameter `'a` declared on fn `flow_ref::deref_mut` appears only in the return type, but here is required to be higher-ranked, which means that `'a` must appear in both argument and return types, #[warn(hr_lifetime_in_assoc_type)] on by default
       --> /Users/nox/src/servo/components/layout/flow_list.rs:124:28
        |>
    124 |>         self.it.next().map(flow_ref::deref_mut)
        |>                            ^^^^^^^^^^^^^^^^^^^
    
  17. added 4 commits that reference this issue on Nov 3, 2016
  18. mbrubeck commented on Dec 14, 2017

    @mbrubeck
    Contributor

    Shouldn't FlowRef::deref_mut at least be an unsafe fn?

  19. jschwe commented on Apr 18, 2024

    @jschwe
    Member

    I just tried compiling servo with the current Rust beta 1.78 and encountered the deny by default lint invalid_reference_casting :

    error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
      --> components/layout/flow_ref.rs:55:18
       |
    55 |         unsafe { &mut *(ptr as *mut dyn Flow) }
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html>
       = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get`
       = note: `#[deny(invalid_reference_casting)]` on by default
    
  20. SimonSapin commented on Apr 19, 2024

    @SimonSapin
    Member

    This solution to this always being UB is to use Arc::as_ptr which does not go through &dyn Flow:

        pub fn deref_mut(this: &mut FlowRef) -> &mut dyn Flow {
            let ptr: *const dyn Flow = Arc::as_ptr(&this.0);
            unsafe { &mut *(ptr as *mut dyn Flow) }
        }

    This leaves the problem that the caller has responsibility to ensure no more than one &mut dyn Flow exist at the same time, so it would be more "honest" to make this an unsafe fn to signal this.

  21. jdm commented on Sep 9, 2025

    @jdm
    Member

    FlowRef doesn't exist in the new engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layout/uncategorizedI-safety

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions