]> git.lizzy.rs Git - rust.git/commitdiff
libcore: Chain must exhaust a before b.
authorSteven Allen <steven@stebalien.com>
Fri, 2 Oct 2015 22:41:06 +0000 (18:41 -0400)
committerSteven Allen <steven@stebalien.com>
Fri, 2 Oct 2015 22:41:06 +0000 (18:41 -0400)
part of #28810

src/libcore/iter.rs

index abf50250dc2ef81b754b6d4eb3fc21428b39243a..bd24cd4609e4bd13f30eb834053d65756a9b62b6 100644 (file)
@@ -1559,7 +1559,12 @@ fn nth(&mut self, mut n: usize) -> Option<A::Item> {
     #[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()
         }