From 6999c421ef7a80104c0799ce8d800a98d0ae85c0 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Fri, 2 Oct 2015 18:41:06 -0400 Subject: [PATCH] libcore: Chain must exhaust a before b. part of #28810 --- src/libcore/iter.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index abf50250dc2ef..bd24cd4609e4b 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1559,7 +1559,12 @@ impl Iterator for Chain where #[inline] fn last(self) -> Option { 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() }