From ee84ec1fa183dbfa9ce2e26e6e8c12ded3ffddb6 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Fri, 21 Oct 2016 19:18:08 +0200 Subject: [PATCH] vec: Add a debug assertion where TrustedLen is used --- src/libcollections/vec.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 50ad48567472..8bed02c79e0a 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1578,7 +1578,13 @@ impl IsTrustedLen for I where I: Iterator { } impl IsTrustedLen for I where I: TrustedLen { fn trusted_len(&self) -> Option { - self.size_hint().1 + let (low, high) = self.size_hint(); + if let Some(high_value) = high { + debug_assert_eq!(low, high_value, + "TrustedLen iterator's size hint is not exact: {:?}", + (low, high)); + } + high } }