Skip to content

A new lint for an assignment statement a = b = c #6576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fiveseven-lambda opened this issue Jan 11, 2021 · 3 comments · Fixed by #9379
Closed

A new lint for an assignment statement a = b = c #6576

fiveseven-lambda opened this issue Jan 11, 2021 · 3 comments · Fixed by #9379
Assignees
Labels
A-lint Area: New lints good first issue These issues are a good way to get started with Clippy

Comments

@fiveseven-lambda
Copy link

fiveseven-lambda commented Jan 11, 2021

What it does

regarding to: https://stackoverflow.com/questions/65661530/why-can-assignment-operator-be-chained-in-rust

One might assume an assignment statement a = b = c; to be equivalent to a = c; b = c;, but it isn't.

There seems to be very few cases, if any, where we would intentionally write a = b = c;.

It would be nice if clippy warned such an assignment.

Categories (optional)

  • Kind: correctness

Drawbacks

None.

Example

a = b = c;

Could be written as:

b = c;
a = ();

Or the programmer might have intended:

a = c;
b = c;
@fiveseven-lambda fiveseven-lambda added the A-lint Area: New lints label Jan 11, 2021
@camsteffen
Copy link
Contributor

In practice, I think the programmer will just run into a type error. (Playground)

@fiveseven-lambda
Copy link
Author

@camsteffen You used Vec::with_capacity in your example function, but if you only try debug print like this, it compiles with no warning about a = b = c;.

@camsteffen camsteffen added the good first issue These issues are a good way to get started with Clippy label Feb 8, 2021
@roynrishingha
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good first issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants