rust-lang / rust-lang/rust-clippy

Improve `indexing_slicing` help message

Open
#2,866 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement L-suggestion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

The help message reported by the indexing_slicing lint could be improved to be more specific. Currently its reports are relatively generic suggestions, i.e. slicing may panic. Consider using .get(..n) or .get_mut(..n) instead.

It would be useful if we figured out whether get() or get_mut() were the right function to suggest and reported the index/span's actual value. After these changes the above example might look something like slicing may panic. Consider using .get_mut(..3) instead

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 locating the indexing_slicing lint implementation and its existing tests. Check how the lint determines whether get() or get_mut() applies and how it represents the index or span; done means diagnostics suggest the appropriate method and include the actual value, with tests covering the improved message.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.