Skip to content

Commit f492ec4

Browse files
committed
Auto merge of #28818 - Stebalien:fix-iter-chain-order, r=alexcrichton
part of #28810
2 parents d2047bc + 6999c42 commit f492ec4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/libcore/iter.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,12 @@ impl<A, B> Iterator for Chain<A, B> where
15591559
#[inline]
15601560
fn last(self) -> Option<A::Item> {
15611561
match self.state {
1562-
ChainState::Both => self.b.last().or(self.a.last()),
1562+
ChainState::Both => {
1563+
// Must exhaust a before b.
1564+
let a_last = self.a.last();
1565+
let b_last = self.b.last();
1566+
b_last.or(a_last)
1567+
},
15631568
ChainState::Front => self.a.last(),
15641569
ChainState::Back => self.b.last()
15651570
}

0 commit comments

Comments
 (0)