rust-lang / rust-lang/rust

`get_unchecked` has incorrect precondition in `impl SliceIndex<[T]> for ops::Range<usize>`

Open
#155,312 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

get_unchecked in impl SliceIndex<[T]> for ops::Range<usize> assumes that Range.start <= Range.end, but this cannot be justified from the safety preconditions in the trait. Notably ranges with Range.start > Range.end are empty ranges and thus always in-bounds.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the SliceIndex<T> trait safety preconditions and the impl SliceIndex<T> for ops::Range<usize> implementation mentioned in the issue. Check how empty ranges with Range.start > Range.end are treated and identify the existing tests around unchecked slice indexing. Done means the implementation's precondition is justified by the trait contract for every valid range.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.