about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteven Allen <steven@stebalien.com>2015-10-02 18:41:06 -0400
committerSteven Allen <steven@stebalien.com>2015-10-02 18:41:06 -0400
commit6999c421ef7a80104c0799ce8d800a98d0ae85c0 (patch)
treee645a915ec11d288800eb9a888a1cdfef4e9996b
parentef07d7dd40e33d7af95c7b00717503730ce69c11 (diff)
downloadrust-6999c421ef7a80104c0799ce8d800a98d0ae85c0.tar.gz
rust-6999c421ef7a80104c0799ce8d800a98d0ae85c0.zip
libcore: Chain must exhaust a before b.
part of #28810
-rw-r--r--src/libcore/iter.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index abf50250dc2..bd24cd4609e 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -1559,7 +1559,12 @@ impl<A, B> Iterator for Chain<A, B> where
     #[inline]
     fn last(self) -> Option<A::Item> {
         match self.state {
-            ChainState::Both => self.b.last().or(self.a.last()),
+            ChainState::Both => {
+                // Must exhaust a before b.
+                let a_last = self.a.last();
+                let b_last = self.b.last();
+                b_last.or(a_last)
+            },
             ChainState::Front => self.a.last(),
             ChainState::Back => self.b.last()
         }