Skip to content

New lint: use slice.first() instead of slice.get(0) #8851

Closed
@equal-l2

Description

@equal-l2

What it does

Detects slice.get(0) and suggests replacement with slice.first().

Lint Name

slice_get_zero

Category

style

Advantage

No magic numbers.

Drawbacks

first() is longer than get(0) by 1 character.

Example

let v = vec![0, 1, 2];
println!("{}", vec.get(0));

Could be written as:

let v = vec![0, 1, 2];
println!("{}", vec.first());

Metadata

Metadata

Assignees

Labels

A-lintArea: New lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions