about summary refs log tree commit diff
path: root/library/alloc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-11-27 11:31:26 +0000
committerbors <bors@rust-lang.org>2021-11-27 11:31:26 +0000
commit5fd3a5c7c175f228afaf5fc6ff00c177b83d8055 (patch)
tree426581ff89fd3fb3420ab8cdd1a2941d4aa3cca0 /library/alloc
parent0881b3abe424034b0c69b99632b64b355057f203 (diff)
parent3f9b26dc64a2068d30027fd29ffbbfe07663419f (diff)
downloadrust-5fd3a5c7c175f228afaf5fc6ff00c177b83d8055.tar.gz
rust-5fd3a5c7c175f228afaf5fc6ff00c177b83d8055.zip
Auto merge of #89916 - the8472:advance_by-avoid-err-0, r=dtolnay
Fix Iterator::advance_by contract inconsistency

The `advance_by(n)` docs state that in the error case `Err(k)` that k is always less than n.
It also states that `advance_by(0)` may return `Err(0)` to indicate an exhausted iterator.
These statements are inconsistent.
Since only one implementation (Skip) actually made use of that I changed it to return Ok(()) in that case too.

While adding some tests I also found a bug in `Take::advance_back_by`.
Diffstat (limited to 'library/alloc')
-rw-r--r--library/alloc/tests/vec.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs
index 00a878c0794..77314282532 100644
--- a/library/alloc/tests/vec.rs
+++ b/library/alloc/tests/vec.rs
@@ -985,6 +985,9 @@ fn test_into_iter_advance_by() {
 
     assert_eq!(i.advance_by(usize::MAX), Err(0));
 
+    i.advance_by(0).unwrap();
+    i.advance_back_by(0).unwrap();
+
     assert_eq!(i.len(), 0);
 }