rust-lang / rust-lang/rust-clippy
[lint request] unnecessary_slice_transmute
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Some people transmute a (T* [const, mut], usize) into a &[T]/&mut [T]/* const[T]/*mut [T] unnecessarily and vice-versa, instead of using the from_raw_parts methods and or (slice.as_ptr(), slice.len()) (yeah, really).
We should probably cover also the case where the pointer type and the element type of the slice differ. A pointer is a pointer, so the transmute won't care, but they should just be casting the stuff around and using the proper methods instead of relying on the unspecified slice layout.
We should detect this and tell people to use the proper methods instead. We probably want to detect the incorrect (usize, T* [const, mut]) cases as well, and tell people to also use the correct methods instead.
If people are doing this inside a macro... we should warn anyways.
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
No source files, tests, or entry points are named in the issue. Start by reading Clippy's existing transmute lint implementations and the Rust APIs for slice construction and pointer/length conversion; done means the requested slice transmute patterns, including reversed tuple order, differing element types, and macro usage, are detected with appropriate guidance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100