Skip to content

Add a USELESS_LET_IF_SEQ lint #814

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

Merged
merged 1 commit into from
May 29, 2016
Merged

Add a USELESS_LET_IF_SEQ lint #814

merged 1 commit into from
May 29, 2016

Conversation

mcarton
Copy link
Member

@mcarton mcarton commented Mar 30, 2016

Fix #15. Fix #636.

span_lint_and_then(cx,
USELESS_LET_IF_SEQ,
span,
"`let foo;`/`if .. { foo = ..; }` sequence detected",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m open to suggestions for a good error message and short description (TODO is not descriptive enough 😝).

@llogiq
Copy link
Contributor

llogiq commented Mar 30, 2016

I'm curious how this handles more complex cases (E.g. with early return, loops or other statements inbetween definition and initialization, etc.

The reason for this being unidiomatic is that it treats if as a statement (which it is in C/Java/Python/..), whereas it is an expression in Rust.

@llogiq
Copy link
Contributor

llogiq commented Apr 1, 2016

Regarding the error message, how about: if _ { .. } else { .. } is an expression. Rustic code uses it as such: [suggestion here]

@llogiq
Copy link
Contributor

llogiq commented Apr 23, 2016

@mcarton do you need help on this?

@mcarton
Copy link
Member Author

mcarton commented Apr 23, 2016

I completely forgot about this 😅

@llogiq
Copy link
Contributor

llogiq commented Apr 23, 2016

I periodically try to go through our PR queue and look if I can merge something or ping someone. 😄

@llogiq
Copy link
Contributor

llogiq commented May 26, 2016

And again, it's been more than a month. I'd still like to see more tests for this, and I'm not sure if it needs a rustup or just rebasing.

@mcarton mcarton force-pushed the let_mut_if branch 3 times, most recently from fe3c999 to 42d9d6b Compare May 27, 2016 19:07
@mcarton
Copy link
Member Author

mcarton commented May 27, 2016

@llogiq rebased and added some tests.

use utils::{snippet, span_lint_and_then};

/// **What it does:** This lint checks for variable declarations immediatly followed by a
/// conditionnal affectation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"conditional", otherwise r+

will merge once I get home

@Manishearth Manishearth merged commit cbc430a into master May 29, 2016
@Manishearth Manishearth deleted the let_mut_if branch May 29, 2016 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants