From fe8de17fa4d682c297319862fe093fe104072238 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 5 Oct 2024 09:13:59 +0300 Subject: [PATCH 1/3] Add test demonstrating the splice panic. --- Cargo.toml | 2 +- src/vec/tests/iter.rs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2bc16881..c0d56191 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ keywords = [ license = "MIT" readme = "README.md" repository = "https://github.com/ferrilab/bitvec" -rust-version = "1.56" +rust-version = "1.81" [features] alloc = [ diff --git a/src/vec/tests/iter.rs b/src/vec/tests/iter.rs index 217f5337..0eaabafe 100644 --- a/src/vec/tests/iter.rs +++ b/src/vec/tests/iter.rs @@ -38,4 +38,13 @@ fn splice() { let mut bv = bitvec![0, 1, 0, 0, 1]; drop(bv.splice(2 .. 2, Some(true))); assert_eq!(bv, bits![0, 1, 1, 0, 0, 1]); + + let mut bv = bitvec![0, 1, 0, 0, 1]; + drop(bv.splice( + 2 .. 2, + (0usize .. 2).flat_map(|index| { + let array = BitArray::<_, Lsb0>::from(index); + array.into_iter().take(2) + }), + )); } From 49a681c7f815c0b669abcbc7cbae936fd1539311 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 5 Oct 2024 09:20:01 +0300 Subject: [PATCH 2/3] Fix #280. --- src/vec/iter.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vec/iter.rs b/src/vec/iter.rs index afa3848a..af1aad2a 100644 --- a/src/vec/iter.rs +++ b/src/vec/iter.rs @@ -682,7 +682,7 @@ where self.drain.move_tail(len); } let filled = self.drain.fill(collected.by_ref()); - debug_assert_eq!(filled, FillStatus::EmptyInput); + debug_assert_eq!(filled, FillStatus::FullSpan); debug_assert_eq!(collected.len(), 0); } } From 50655588b86a13f871b940437a0e814e62583150 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Sat, 5 Oct 2024 09:25:22 +0300 Subject: [PATCH 3/3] Improve docs of `FillStatus` variants. --- src/vec/iter.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vec/iter.rs b/src/vec/iter.rs index af1aad2a..ff891920 100644 --- a/src/vec/iter.rs +++ b/src/vec/iter.rs @@ -540,8 +540,9 @@ where #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] enum FillStatus { /// The drain span is completely filled. + /// Note in this case, the replacement source may or may not be exhausted. FullSpan = 0, - /// The replacement source is completely exhausted. + /// The replacement source is completely exhausted, but the drain span is not filled yet. EmptyInput = 1, }