rust-lang / rust-lang/rust-clippy
Pedantic suggestion of using an array type definition
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Suggests to define a array type alias to simplify the code, making it more readable.
Lint Name
use_array_type_alias
Category
pedantic
Advantage
No response
Drawbacks
No response
Example
In this small program from the Benchmarks Game:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/mandelbrot-rust-6.html
There are lines of code like:
fn clr_pixels_nle(v : &[f64x2;4], f: f64, pix8 : &mut u8){
...
fn calc_sum(r: &mut [f64x2;4], i : &mut[f64x2;4], sum : &mut[f64x2;4], init_r: &[f64x2;4], init_i : f64x2){
...
fn mand8(init_r: &[f64x2;4], init_i : f64x2) -> u8 {
...
I suggest to add a lint in clippy::pedantic that suggests to define something like:
type Array1 = [f64x2; 4];
And then use that type in the above code, like:
fn clr_pixels_nle(v: &Array1, f: f64, pix8: &mut u8) {
...
fn calc_sum(r: &mut Array1, i: &mut Array1, sum: &mut Array1, init_r: &Array1, init_i: f64x2) {
...
fn mand8(init_r: &Array1, init_i: f64x2) -> u8 {
...
Defining type aliases to simplify array arguments in Rust code is quite under-used.
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 proposed clippy::pedantic lint named use_array_type_alias and review the Rust examples in the issue, especially the repeated [f64x2; 4] arguments. Define the applicability and expected diagnostic, then add the lint and tests showing when the array type alias suggestion is emitted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100