From ee84ec1fa183dbfa9ce2e26e6e8c12ded3ffddb6 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Fri, 21 Oct 2016 19:18:08 +0200 Subject: vec: Add a debug assertion where TrustedLen is used --- src/libcollections/vec.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 50ad4856747..8bed02c79e0 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 } } -- cgit 1.4.1-3-g733a5