Skip to content

Lint suggestion: explicit construction of tuple struct by named fields #7985

@alice-i-cecile

Description

@alice-i-cecile

What it does

What does this lint do?

Detects if someone has decided to create a tuple struct by its named (.0, .1 etc) fields.

See this playground for proof that this actually works.

Categories (optional)

  • Kind: clippy::style

What is the advantage of the recommended code over the original code

Constructing tuple structs by their named fields is extremely unidiomatic, verbose and unclear.

Drawbacks

May be spurious if users are using struct update syntax with tuple structs.

Example

struct MyTuple(isize, isize);

let my_tuple = MyTuple {
  0: 1,
  1: 2,
};

Could be written as:

struct MyTuple(isize, isize);

let my_tuple = MyTuple(0, 1);

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