From 4727b92754be504c37a62dfe806999e40a3339f6 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 12 Oct 2017 18:00:44 +0200 Subject: [PATCH] Remove usage of unstable feature conservative_impl_trait in layout --- components/layout/flow.rs | 4 ++-- components/layout/flow_list.rs | 30 ++++++++++++++++++++++++++++-- components/layout/lib.rs | 1 - 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/components/layout/flow.rs b/components/layout/flow.rs index b5afce9471b..05512724843 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -32,7 +32,7 @@ use display_list_builder::{DisplayListBuildState, StackingContextCollectionState use euclid::{Transform3D, Point2D, Vector2D, Rect, Size2D}; use flex::FlexFlow; use floats::{Floats, SpeculatedFloatPlacement}; -use flow_list::{FlowList, MutFlowListIterator}; +use flow_list::{FlowList, FlowListIterator, MutFlowListIterator}; use flow_ref::{FlowRef, WeakFlowRef}; use fragment::{CoordinateSystem, Fragment, FragmentBorderBoxIterator, Overflow}; use gfx_traits::StackingContextId; @@ -459,7 +459,7 @@ pub fn base(this: &T) -> &BaseFlow { } /// Iterates over the children of this immutable flow. -pub fn child_iter<'a>(flow: &'a Flow) -> impl Iterator { +pub fn child_iter<'a>(flow: &'a Flow) -> FlowListIterator { base(flow).children.iter() } diff --git a/components/layout/flow_list.rs b/components/layout/flow_list.rs index 97fd6dbc89f..2960579762e 100644 --- a/components/layout/flow_list.rs +++ b/components/layout/flow_list.rs @@ -7,6 +7,7 @@ use flow_ref::FlowRef; use serde::ser::{Serialize, SerializeSeq, Serializer}; use serde_json::{Map, Value, to_value}; use std::collections::{LinkedList, linked_list}; +use std::ops::Deref; use std::sync::Arc; /// This needs to be reworked now that we have dynamically-sized types in Rust. @@ -53,6 +54,10 @@ pub struct MutFlowListIterator<'a> { it: linked_list::IterMut<'a, FlowRef>, } +pub struct FlowListIterator<'a> { + it: linked_list::Iter<'a, FlowRef>, +} + impl FlowList { /// Add an element last in the list /// @@ -101,8 +106,10 @@ impl FlowList { /// SECURITY-NOTE(pcwalton): This does not hand out `FlowRef`s by design. Do not add a method /// to do so! See the comment above in `FlowList`. #[inline] - pub fn iter<'a>(&'a self) -> impl DoubleEndedIterator { - self.flows.iter().map(|flow| &**flow) + pub fn iter<'a>(&'a self) -> FlowListIterator { + FlowListIterator { + it: self.flows.iter(), + } } /// Provide a forward iterator with mutable references @@ -150,12 +157,31 @@ impl FlowList { } } +impl<'a> DoubleEndedIterator for FlowListIterator<'a> { + fn next_back(&mut self) -> Option<&'a Flow> { + self.it.next_back().map(Deref::deref) + } +} + impl<'a> DoubleEndedIterator for MutFlowListIterator<'a> { fn next_back(&mut self) -> Option<&'a mut Flow> { self.it.next_back().map(FlowRef::deref_mut) } } +impl<'a> Iterator for FlowListIterator<'a> { + type Item = &'a Flow; + #[inline] + fn next(&mut self) -> Option<&'a Flow> { + self.it.next().map(Deref::deref) + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.it.size_hint() + } +} + impl<'a> Iterator for MutFlowListIterator<'a> { type Item = &'a mut Flow; #[inline] diff --git a/components/layout/lib.rs b/components/layout/lib.rs index efab7c69752..eb337c4b015 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -4,7 +4,6 @@ #![deny(unsafe_code)] #![feature(box_patterns)] -#![feature(conservative_impl_trait)] #![feature(raw)] extern crate app_units;