Inconsistent behavior when indexing slice/BTreeSet with `1..=0`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
use std::collections::BTreeSet;
fn main() {
assert_eq!(&[123][1..=0], []);
let set = BTreeSet::from_iter([123]);
assert_eq!(set.range(1..=0).copied().collect::<Vec<i32>>(), &[]);
}
I expected to see this happen: Either both should panic since the range start is greater than the range end, or both should yield 0 items.
Instead, this happened: The slice indexing assertion passes, but the BTreeSet operation panics:
range start is greater than range end in BTreeSet
Meta
Reproduces on stable 1.80 and current nightly.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer comparing slice indexing with BTreeSet::range(1..=0), and confirm the behavior on stable and nightly Rust. Trace the relevant standard-library implementations and existing range tests, then determine which behavior should be made consistent. Done means the chosen behavior is consistent and covered by regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100