diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-15 03:03:53 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2016-03-15 03:03:53 +0530 |
commit | aea8d8959dcb157a8cc381f1403246ce8ca1ca00 (patch) | |
tree | 57c79277ab7194f01846c088285f0d76f2a751e1 /components/layout/flow.rs | |
parent | 881d6b4220f2391a22d4ea73b79415071626501f (diff) | |
parent | 539f839958650a0f08f3db444e1d57494e0e9830 (diff) | |
download | servo-aea8d8959dcb157a8cc381f1403246ce8ca1ca00.tar.gz servo-aea8d8959dcb157a8cc381f1403246ce8ca1ca00.zip |
Auto merge of #9976 - bholley:remove_trait_lifetimes, r=SimonSapin
Remove lifetimes from Style/Layout traits
Right now, there's a huge amount of complexity in T{Node,Element,Document} and friends because of the lifetime parameter.
Before I started generalizing this code for use by Gecko, these wrappers were plain structs. They had (and still have) a phantom lifetime associated with them to prevent references to DOM nodes from leaking past the end of restyle, when they might be invalidated by a GC.
When I generalized them, I decided to put the lifetime on the trait as well, since there are some situations where the lifetime is, in fact, necessary. Specifically, they are necessary for the compiler to understand that all the things borrowed from all the nodes and elements and so on have the same lifetime (the lifetime of the restyle), rather than the lifetime of whichever particular element or node pointer the value was borrowed from. This come up in situations where we do |let el = node.as_element()| or |let n = el.as_node()| and then borrow something from the result. The compiler thinks the borrow lifetime is that of |el| or |n|, when it's actually longer.
In practice though, I think the style and layout algorithms we use don't run into this issue much, and we can hack around it where it comes up. So I think we should remove the lifetimes from the traits, which will let us aggregate the embedding-provided traits together onto a single meta-trait and significantly simplify the code.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9976)
<!-- Reviewable:end -->
Diffstat (limited to 'components/layout/flow.rs')
-rw-r--r-- | components/layout/flow.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/components/layout/flow.rs b/components/layout/flow.rs index 1dd4b386ad8..b61540dfb3b 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -483,7 +483,7 @@ pub trait ImmutableFlowUtils { fn need_anonymous_flow(self, child: &Flow) -> bool; /// Generates missing child flow of this flow. - fn generate_missing_child_flow<'ln, N: ThreadSafeLayoutNode<'ln>>(self, node: &N) -> FlowRef; + fn generate_missing_child_flow<N: ThreadSafeLayoutNode>(self, node: &N) -> FlowRef; /// Returns true if this flow contains fragments that are roots of an absolute flow tree. fn contains_roots_of_absolute_flow_tree(&self) -> bool; @@ -1272,7 +1272,7 @@ impl<'a> ImmutableFlowUtils for &'a Flow { /// FIXME(pcwalton): This duplicates some logic in /// `generate_anonymous_table_flows_if_necessary()`. We should remove this function eventually, /// as it's harder to understand. - fn generate_missing_child_flow<'ln, N: ThreadSafeLayoutNode<'ln>>(self, node: &N) -> FlowRef { + fn generate_missing_child_flow<N: ThreadSafeLayoutNode>(self, node: &N) -> FlowRef { let mut style = node.style().clone(); match self.class() { FlowClass::Table | FlowClass::TableRowGroup => { |